summaryrefslogtreecommitdiff
path: root/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb')
-rw-r--r--db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb43
1 files changed, 0 insertions, 43 deletions
diff --git a/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb b/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb
deleted file mode 100644
index a526001a91e..00000000000
--- a/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-class AddUniqueConstraintToProjectFeaturesProjectId < ActiveRecord::Migration[4.2]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- class ProjectFeature < ActiveRecord::Base
- self.table_name = 'project_features'
-
- include EachBatch
- end
-
- def up
- remove_duplicates
-
- add_concurrent_index :project_features, :project_id, unique: true, name: 'index_project_features_on_project_id_unique'
- remove_concurrent_index_by_name :project_features, 'index_project_features_on_project_id'
- rename_index :project_features, 'index_project_features_on_project_id_unique', 'index_project_features_on_project_id'
- end
-
- def down
- rename_index :project_features, 'index_project_features_on_project_id', 'index_project_features_on_project_id_old'
- add_concurrent_index :project_features, :project_id
- remove_concurrent_index_by_name :project_features, 'index_project_features_on_project_id_old'
- end
-
- private
-
- def remove_duplicates
- features = ProjectFeature
- .select('MAX(id) AS max, COUNT(id), project_id')
- .group(:project_id)
- .having('COUNT(id) > 1')
-
- features.each do |feature|
- ProjectFeature
- .where(project_id: feature['project_id'])
- .where('id <> ?', feature['max'])
- .each_batch { |batch| batch.delete_all }
- end
- end
-end