debian-mirror-gitlab/db/migrate/20160610201627_migrate_users_notification_level.rb

26 lines
807 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
class MigrateUsersNotificationLevel < ActiveRecord::Migration[4.2]
2017-08-17 22:00:37 +05:30
DOWNTIME = false
# Migrates only users who changed their default notification level :participating
# creating a new record on notification settings table
2017-08-17 22:00:37 +05:30
DOWNTIME = false
def up
execute(%Q{
INSERT INTO notification_settings
(user_id, level, created_at, updated_at)
(SELECT id, notification_level, created_at, updated_at FROM users WHERE notification_level != 1)
})
end
# Migrates from notification settings back to user notification_level
# If no value is found the default level of 1 will be used
def down
execute(%Q{
UPDATE users u SET
notification_level = COALESCE((SELECT level FROM notification_settings WHERE user_id = u.id AND source_type IS NULL), 1)
})
end
end