summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-03-13 18:10:53 +0100
committerAndreas Brandl <abrandl@gitlab.com>2018-03-14 17:51:47 +0100
commit5f35ea146adf3b96546e5dc6f69927d6ad7bcb1c (patch)
treeeaef986b379cc9181e5edc1b323a01ba9c76c264 /lib
parent7e4fcbf9bec34bb4c8e023f3726a99273850f800 (diff)
downloadgitlab-ce-5f35ea146adf3b96546e5dc6f69927d6ad7bcb1c.tar.gz
Fix concurrency issue with migration for user_interacted_projects table.ab-44205-user_interacted_projects-migration
The concurrency issue originates from inserts on `user_interacted_projects` from the app while running the post-deploy migration. This change comes with a strategy to lock the table while removing duplicates and creating the unique index (and similar for FK constraints). Also, we'll have a non-unique index until the post-deploy migration is finished to speed up queries during that time. Closes #44205.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/database/migration_helpers.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index dbe6259fce7..21287a8efd0 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -859,6 +859,19 @@ into similar problems in the future (e.g. when new tables are created).
BackgroundMigrationWorker.perform_in(delay_interval * index, job_class_name, [start_id, end_id])
end
end
+
+ def foreign_key_exists?(table, column)
+ foreign_keys(table).any? do |key|
+ key.options[:column] == column.to_s
+ end
+ end
+
+ # Rails' index_exists? doesn't work when you only give it a table and index
+ # name. As such we have to use some extra code to check if an index exists for
+ # a given name.
+ def index_exists_by_name?(table, index)
+ indexes(table).map(&:name).include?(index)
+ end
end
end
end