mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-25 18:26:10 +01:00
#1955: Change the logic concerning unused tags and add CHANGELOG entries
This commit is contained in:
parent
1c61f9cffb
commit
ad0f617d7c
2 changed files with 29 additions and 6 deletions
|
|
@ -65,12 +65,21 @@ class AddUserIdToTag < ActiveRecord::Migration[5.2]
|
|||
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
|
||||
# Set all unowned tags to the only user, if there's only one. Otherwise
|
||||
# remove them since there's no way of knowing who they belong to.
|
||||
if User.all.count == 1
|
||||
uid = User.first.id
|
||||
execute <<-EOQ
|
||||
UPDATE tags
|
||||
SET user_id = #{uid}
|
||||
WHERE user_id IS NULL
|
||||
EOQ
|
||||
else
|
||||
execute <<-EOQ
|
||||
DELETE FROM tags
|
||||
WHERE user_id IS NULL
|
||||
EOQ
|
||||
end
|
||||
end
|
||||
def self.down
|
||||
remove_column :tags, :user_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue