summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-06-03 15:49:34 -0300
committerFelipe Artur <felipefac@gmail.com>2016-06-03 16:46:10 -0300
commit8450fe3074140b86e7d2e5a85d2cdb65051906ee (patch)
treea3c14da2bd14f088e182c3b9366c3fff62b747a7
parentca3c5c295ed653b483fe81c3918ffe60f46666b9 (diff)
downloadgitlab-ce-8450fe3074140b86e7d2e5a85d2cdb65051906ee.tar.gz
Add index to notification settings
-rw-r--r--CHANGELOG1
-rw-r--r--db/migrate/20160603180330_remove_duplicated_notification_settings.rb7
-rw-r--r--db/migrate/20160603182247_add_index_to_notification_settings.rb9
-rw-r--r--lib/gitlab/database/migration_helpers.rb6
4 files changed, 22 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 7215a919d79..bcb7e290ede 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -34,6 +34,7 @@ v 8.9.0 (unreleased)
- Cache project build count in sidebar nav
- Reduce number of queries needed to render issue labels in the sidebar
- Improve error handling importing projects
+ - Remove duplicated notification settings
- Put project Files and Commits tabs under Code tab
v 8.8.4
diff --git a/db/migrate/20160603180330_remove_duplicated_notification_settings.rb b/db/migrate/20160603180330_remove_duplicated_notification_settings.rb
new file mode 100644
index 00000000000..c2fcac4c53d
--- /dev/null
+++ b/db/migrate/20160603180330_remove_duplicated_notification_settings.rb
@@ -0,0 +1,7 @@
+class RemoveDuplicatedNotificationSettings < ActiveRecord::Migration
+ def up
+ execute <<-SQL
+ DELETE FROM notification_settings WHERE id NOT IN ( SELECT min_id from (SELECT MIN(id) as min_id FROM notification_settings GROUP BY user_id, source_type, source_id) as dups )
+ SQL
+ end
+end
diff --git a/db/migrate/20160603182247_add_index_to_notification_settings.rb b/db/migrate/20160603182247_add_index_to_notification_settings.rb
new file mode 100644
index 00000000000..06462042b09
--- /dev/null
+++ b/db/migrate/20160603182247_add_index_to_notification_settings.rb
@@ -0,0 +1,9 @@
+class AddIndexToNotificationSettings < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def change
+ add_concurrent_index :notification_settings, [:user_id, :source_id, :source_type], { unique: true, name: "index_notifications_on_user_id_and_source_id_and_source_type" }
+ end
+end
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index fd14234c558..b88e50748f6 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -19,7 +19,11 @@ module Gitlab
end
if Database.postgresql?
- args << { algorithm: :concurrently }
+ if args[2].present?
+ args[2].merge!({ algorithm: :concurrently })
+ else
+ args << { algorithm: :concurrently }
+ end
end
add_index(*args)