From e13d3ff62e51c2ac52bb15cfcb6e57851ad3c874 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 15 May 2021 13:50:47 -0400 Subject: [PATCH] mix format --- ...x_posts_on_topic_id_and_topic_position.exs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/priv/repo/migrations/20210427022351_add_index_posts_on_topic_id_and_topic_position.exs b/priv/repo/migrations/20210427022351_add_index_posts_on_topic_id_and_topic_position.exs index 89c70ae5..0fa3e2a2 100644 --- a/priv/repo/migrations/20210427022351_add_index_posts_on_topic_id_and_topic_position.exs +++ b/priv/repo/migrations/20210427022351_add_index_posts_on_topic_id_and_topic_position.exs @@ -2,20 +2,25 @@ defmodule Philomena.Repo.Migrations.AddIndexPostsOnTopicIdAndTopicPosition do use Ecto.Migration 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(""" + 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 + from mismatched_ranks + where posts.id=mismatched_ranks.id; + """) + 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) - update posts set topic_position=mismatched_ranks.rank - from mismatched_ranks - where posts.id=mismatched_ranks.id; - """); - execute("create unique index index_posts_on_topic_id_and_topic_position on posts (topic_id, topic_position);"); + "create unique index index_posts_on_topic_id_and_topic_position on posts (topic_id, topic_position);" + ) end def down do - 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("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 end