#1955: Fix the migration queries

This commit is contained in:
Jyri-Petteri Paloposki 2019-06-27 16:48:26 +03:00
parent 6b54962388
commit 1c61f9cffb

View file

@ -43,27 +43,34 @@ class AddUserIdToTag < ActiveRecord::Migration[5.2]
new_tag.save!
# Move all the user's regular todos to the new tag.
connection.execute(<<-EOQ)
execute <<-EOQ
UPDATE taggings ta
JOIN todos t
ON ta.taggable_type = "Todo" AND t.id = ta.taggable_id
SET ta.tag_id = #{new_tag.id}
WHERE t.user_id = #{uid}
WHERE t.user_id = #{uid} AND ta.tag_id = #{tid}
EOQ
# Move all the user's recurring todos to the new tag.
connection.execute(<<-EOQ)
execute <<-EOQ
UPDATE taggings ta
JOIN recurring_todos t
ON ta.taggable_type = "RecurringTodo" AND t.id = ta.taggable_id
SET ta.tag_id = #{new_tag.id}
WHERE t.user_id = #{uid}
WHERE t.user_id = #{uid} AND ta.tag_id = #{tid}
EOQ
end
tag.user_id = uids[0]
tag.save!
end
# Set all unowned tags to user ID #1, because they're unused.
execute <<-EOQ
UPDATE tags
SET user_id = 1
WHERE user_id IS NULL
EOQ
end
def self.down
remove_column :tags, :user_id