mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
#1955: Fix the migration queries
This commit is contained in:
parent
6b54962388
commit
1c61f9cffb
1 changed files with 64 additions and 57 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue