diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index ed6bdc25ce6..aad8637404c 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -22,6 +22,7 @@ task "import:ensure_consistency" => :environment do update_users update_groups update_tag_stats + update_topic_users create_category_definitions log "Done!" @@ -29,6 +30,10 @@ end MS_SPEND_CREATING_POST ||= 5000 +# -- TODO: We need to check the queries are actually adding/updating the necessary +# data, post migration. The ON CONFLICT DO NOTHING may cause the clauses to be ignored +# when we actually need them to run. + def insert_post_timings log "Inserting post timings..." @@ -415,6 +420,29 @@ def update_tag_stats Tag.ensure_consistency! end +def update_topic_users + log "Updating topic users..." + + DB.exec <<-SQL + WITH X AS ( + SELECT p.topic_id + , p.user_id + FROM posts p + JOIN topics t ON t.id = p.topic_id + WHERE p.deleted_at IS NULL + AND t.deleted_at IS NULL + AND NOT p.hidden + AND t.visible + ) + UPDATE topic_users tu + SET posted = 't' + FROM X + WHERE tu.topic_id = X.topic_id + AND tu.user_id = X.user_id + AND posted = 'f' + SQL +end + def create_category_definitions log "Creating category definitions" Category.ensure_consistency!