A platform for community discussion. Free, open, simple.
rake task should allow reordering posts of single topic
Gerhard Schlager64f2086ccaf9
diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rakeindex 0148fbcfdf5..3c17bc1e3bd 100644--- a/lib/tasks/posts.rake+++ b/lib/tasks/posts.rake@@ -279,11 +279,11 @@ task 'posts:refresh_emails', [:topic_id] => [:environment] do |_, args|enddesc 'Reorders all posts based on their creation_date'-task 'posts:reorder_posts' => :environment do+task 'posts:reorder_posts', [:topic_id] => [:environment] do |_, args|Post.transaction do# update sort_order and flip post_number to prevent# unique constraint violations when updating post_number- Post.exec_sql(<<~SQL)+ builder = SqlBuilder.new(<<~SQL)WITH ordered_posts AS (SELECTid,@@ -292,6 +292,7 @@ task 'posts:reorder_posts' => :environment doPARTITION BY topic_idORDER BY created_at, post_number ) AS new_post_numberFROM posts+ /*where*/)UPDATE posts AS pSET sort_order = o.new_post_number,@@ -300,6 +301,8 @@ task 'posts:reorder_posts' => :environment doWHERE p.id = o.id ANDp.post_number <> o.new_post_numberSQL+ builder.where("topic_id = :topic_id") if args[:topic_id]+ builder.exec(topic_id: args[:topic_id])Notification.exec_sql(<<~SQL)UPDATE notifications AS x