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-06 18:50:54 +0300
committerFelipe Artur <felipefac@gmail.com>2016-06-10 16:58:13 +0300
commit8f6d43e0fea3ce62ec2e8e211755e557f19c51fd (patch)
tree72930d029dd905d7630ec07dd65acb0ac4b0739c /db
parentf29fd65cdde1d769fc89f0cc57ea989765b5068f (diff)
Remove notification level from user model
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20160606192159_remove_notification_setting_not_null_constraints.rb7
-rw-r--r--db/migrate/20160607201627_migrate_users_notification_level.rb24
2 files changed, 31 insertions, 0 deletions
diff --git a/db/migrate/20160606192159_remove_notification_setting_not_null_constraints.rb b/db/migrate/20160606192159_remove_notification_setting_not_null_constraints.rb
new file mode 100644
index 00000000000..c20ac9acdc2
--- /dev/null
+++ b/db/migrate/20160606192159_remove_notification_setting_not_null_constraints.rb
@@ -0,0 +1,7 @@
+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
+end
diff --git a/db/migrate/20160607201627_migrate_users_notification_level.rb b/db/migrate/20160607201627_migrate_users_notification_level.rb
new file mode 100644
index 00000000000..7417d66fef7
--- /dev/null
+++ b/db/migrate/20160607201627_migrate_users_notification_level.rb
@@ -0,0 +1,24 @@
+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