check if env is prod for execute statements in migration

This commit is contained in:
Luna D 2023-05-28 22:47:32 +02:00
parent b70c0a11f6
commit e775d7fdd7
No known key found for this signature in database
GPG key ID: 4B1C63448394F688

View file

@ -51,6 +51,9 @@ defmodule Philomena.Repo.Migrations.RewriteSourceChanges do
create constraint(:image_sources, :image_sources_source_check, check: "source ~* '^https?://'") create constraint(:image_sources, :image_sources_source_check, check: "source ~* '^https?://'")
# These statements should not be ran by the migration in production.
# Run them manually in psql instead.
if System.get_env("MIX_ENV") != "prod" do
execute(""" execute("""
insert into image_sources (image_id, source) insert into image_sources (image_id, source)
select id as image_id, substr(source_url, 1, 255) as source from images select id as image_id, substr(source_url, 1, 255) as source from images
@ -92,6 +95,7 @@ defmodule Philomena.Repo.Migrations.RewriteSourceChanges do
from ranked_removed_source_changes from ranked_removed_source_changes
where "rank" > 1; where "rank" > 1;
""") """)
end
create index(:source_changes, [:image_id], name: "index_source_changes_on_image_id") create index(:source_changes, [:image_id], name: "index_source_changes_on_image_id")
create index(:source_changes, [:user_id], name: "index_source_changes_on_user_id") create index(:source_changes, [:user_id], name: "index_source_changes_on_user_id")