From ac6798877df6d394ab4bc69d55a579c7fd88e7e8 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 22 Feb 2022 23:22:02 +0100 Subject: [PATCH] Add migration for moving smiles to appendables --- .../20220216150127_move_smiles_to_appendables.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/db/migrate/20220216150127_move_smiles_to_appendables.rb b/db/migrate/20220216150127_move_smiles_to_appendables.rb index 2380e146..df3d9789 100644 --- a/db/migrate/20220216150127_move_smiles_to_appendables.rb +++ b/db/migrate/20220216150127_move_smiles_to_appendables.rb @@ -1,6 +1,19 @@ class MoveSmilesToAppendables < ActiveRecord::Migration[6.1] - def up_only + def up execute "INSERT INTO appendables (type, user_id, parent_id, parent_type, content, created_at, updated_at) (SELECT 'Appendable::Reaction' AS type, user_id, answer_id as parent_id, 'Answer' as parent_type, '🙂' AS content, created_at, updated_at FROM smiles)" + + execute "UPDATE notifications n +SET target_type = 'Appendable', target_id = a.id +FROM appendables a, smiles s +WHERE n.target_type = 'Smile' AND s.id = n.target_id AND a.type = 'Appendable::Reaction' AND a.parent_id = s.answer_id" + + execute "INSERT INTO appendables (type, user_id, parent_id, parent_type, content, created_at, updated_at) +(SELECT 'Appendable::Reaction' AS type, user_id, comment_id as parent_id, 'Comment' as parent_type, '🙂' AS content, created_at, updated_at FROM comment_smiles)" + + execute "UPDATE notifications n +SET target_type = 'Appendable', target_id = a.id +FROM appendables a, comment_smiles s +WHERE n.target_type = 'CommentSmile' AND s.id = n.target_id AND a.type = 'Appendable::Reaction' AND a.parent_id = s.comment_id" end end