Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-06-09 22:33:31 +0300
committerFelipe Artur <felipefac@gmail.com>2016-06-10 17:49:30 +0300
commit39ead205de72461e86db07525922f2fab5fff2a9 (patch)
tree5336487bad3b89b5db461788aba9eb7d4b9c3b0f /db
parent8f6d43e0fea3ce62ec2e8e211755e557f19c51fd (diff)
Remove notification level fild from users, improve migrations and specs
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20160607201627_migrate_users_notification_level.rb24
-rw-r--r--db/migrate/20160610140403_remove_notification_setting_not_null_constraints.rb (renamed from db/migrate/20160606192159_remove_notification_setting_not_null_constraints.rb)6
-rw-r--r--db/migrate/20160610201627_migrate_users_notification_level.rb21
-rw-r--r--db/migrate/20160610301627_remove_notification_level_from_users.rb7
4 files changed, 33 insertions, 25 deletions
diff --git a/db/migrate/20160607201627_migrate_users_notification_level.rb b/db/migrate/20160607201627_migrate_users_notification_level.rb
deleted file mode 100644
index 7417d66fef7..00000000000
--- a/db/migrate/20160607201627_migrate_users_notification_level.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-class MigrateUsersNotificationLevel < ActiveRecord::Migration
- # Migrates only users which changes theier default notification level :participating
- # creating a new record on notification settins table
-
- def up
- changed_users = exec_query(%Q{
- SELECT id, notification_level
- FROM users
- WHERE notification_level != 1
- })
-
- changed_users.each do |row|
- uid = row['id']
- u_notification_level = row['notification_level']
-
- execute(%Q{
- INSERT INTO notification_settings
- (user_id, level, created_at, updated_at)
- VALUES
- (#{uid}, #{u_notification_level}, now(), now())
- })
- end
- end
-end
diff --git a/db/migrate/20160606192159_remove_notification_setting_not_null_constraints.rb b/db/migrate/20160610140403_remove_notification_setting_not_null_constraints.rb
index c20ac9acdc2..259abb08e47 100644
--- a/db/migrate/20160606192159_remove_notification_setting_not_null_constraints.rb
+++ b/db/migrate/20160610140403_remove_notification_setting_not_null_constraints.rb
@@ -2,6 +2,10 @@ class RemoveNotificationSettingNotNullConstraints < ActiveRecord::Migration
def up
change_column :notification_settings, :source_type, :string, null: true
change_column :notification_settings, :source_id, :integer, null: true
- change_column :users, :notification_level, :integer, null: true
+ end
+
+ def down
+ change_column :notification_settings, :source_type, :string, null: false
+ change_column :notification_settings, :source_id, :integer, null: false
end
end
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
diff --git a/db/migrate/20160610301627_remove_notification_level_from_users.rb b/db/migrate/20160610301627_remove_notification_level_from_users.rb
new file mode 100644
index 00000000000..8afb14df2cf
--- /dev/null
+++ b/db/migrate/20160610301627_remove_notification_level_from_users.rb
@@ -0,0 +1,7 @@
+class RemoveNotificationLevelFromUsers < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ def change
+ remove_column :users, :notification_level, :integer
+ end
+end