2018-11-13 02:27:31 -05:00
|
|
|
class MigrateUsersNotificationLevel < ActiveRecord::Migration[4.2]
|
2017-02-28 00:38:37 -05:00
|
|
|
DOWNTIME = false
|
|
|
|
|
2016-06-09 15:33:31 -04:00
|
|
|
# Migrates only users who changed their default notification level :participating
|
|
|
|
# creating a new record on notification settings table
|
|
|
|
|
2017-02-22 10:13:02 -05:00
|
|
|
DOWNTIME = false
|
|
|
|
|
2016-06-09 15:33:31 -04:00
|
|
|
def up
|
2017-02-22 17:39:43 -05:00
|
|
|
execute(%Q{
|
2016-06-09 15:33:31 -04:00
|
|
|
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
|
2017-02-22 17:39:43 -05:00
|
|
|
execute(%Q{
|
2016-06-09 15:33:31 -04:00
|
|
|
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
|