mix format

This commit is contained in:
byte[] 2021-05-15 13:50:47 -04:00
parent 952d7bca4f
commit e13d3ff62e

View file

@ -2,20 +2,25 @@ defmodule Philomena.Repo.Migrations.AddIndexPostsOnTopicIdAndTopicPosition do
use Ecto.Migration use Ecto.Migration
def up do def up do
execute("drop index index_posts_on_topic_id_and_topic_position;"); execute("drop index index_posts_on_topic_id_and_topic_position;")
execute(
""" execute("""
with mismatched_ranks as (select id,rank from (select id, topic_position, (rank() over (partition by topic_id order by created_at,id asc))-1 as rank from posts) s where s.topic_position <> s.rank) with mismatched_ranks as (select id,rank from (select id, topic_position, (rank() over (partition by topic_id order by created_at,id asc))-1 as rank from posts) s where s.topic_position <> s.rank)
update posts set topic_position=mismatched_ranks.rank update posts set topic_position=mismatched_ranks.rank
from mismatched_ranks from mismatched_ranks
where posts.id=mismatched_ranks.id; where posts.id=mismatched_ranks.id;
"""); """)
execute("create unique index index_posts_on_topic_id_and_topic_position on posts (topic_id, topic_position);");
execute(
"create unique index index_posts_on_topic_id_and_topic_position on posts (topic_id, topic_position);"
)
end end
def down do def down do
execute("drop index index_posts_on_topic_id_and_topic_position;"); execute("drop index index_posts_on_topic_id_and_topic_position;")
execute("create index index_posts_on_topic_id_and_topic_position on public.posts (topic_id, topic_position);");
end
execute(
"create index index_posts_on_topic_id_and_topic_position on public.posts (topic_id, topic_position);"
)
end
end end