diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-06-09 16:33:31 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-06-10 11:49:30 -0300 |
commit | 39ead205de72461e86db07525922f2fab5fff2a9 (patch) | |
tree | 5336487bad3b89b5db461788aba9eb7d4b9c3b0f /db/migrate/20160610201627_migrate_users_notification_level.rb | |
parent | 8f6d43e0fea3ce62ec2e8e211755e557f19c51fd (diff) | |
download | gitlab-ce-39ead205de72461e86db07525922f2fab5fff2a9.tar.gz |
Remove notification level fild from users, improve migrations and specsissue_3359_2
Diffstat (limited to 'db/migrate/20160610201627_migrate_users_notification_level.rb')
-rw-r--r-- | db/migrate/20160610201627_migrate_users_notification_level.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/db/migrate/20160610201627_migrate_users_notification_level.rb b/db/migrate/20160610201627_migrate_users_notification_level.rb new file mode 100644 index 00000000000..760b766828e --- /dev/null +++ b/db/migrate/20160610201627_migrate_users_notification_level.rb @@ -0,0 +1,21 @@ +class MigrateUsersNotificationLevel < ActiveRecord::Migration + # Migrates only users who changed their default notification level :participating + # creating a new record on notification settings table + + 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 |