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
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-11-15 15:51:28 +0300
committerMichael Kozono <mkozono@gmail.com>2017-11-17 03:51:39 +0300
commitd9e6bbf7252efac4508bb27fe99dccff5500d208 (patch)
tree0b387499667f470ba60c43eb12f63433a8ce7ee3
parentf703b5b88ca524190af521bc4a816a5f11d3f6af (diff)
Fix migration for pre-Postgres 9.5
-rw-r--r--lib/gitlab/background_migration/prepare_untracked_uploads.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/gitlab/background_migration/prepare_untracked_uploads.rb b/lib/gitlab/background_migration/prepare_untracked_uploads.rb
index 9c40cf8aee2..8772092da64 100644
--- a/lib/gitlab/background_migration/prepare_untracked_uploads.rb
+++ b/lib/gitlab/background_migration/prepare_untracked_uploads.rb
@@ -88,9 +88,14 @@ module Gitlab
end
def insert_file_path(file_path)
+ if postgresql_pre_9_5?
+ # No easy way to do ON CONFLICT DO NOTHING before Postgres 9.5 so just use Rails
+ return UntrackedFile.where(path: file_path).first_or_create
+ end
+
table_columns_and_values = 'untracked_files_for_uploads (path, created_at, updated_at) VALUES (?, ?, ?)'
- sql = if Gitlab::Database.postgresql?
+ sql = if postgresql?
"INSERT INTO #{table_columns_and_values} ON CONFLICT DO NOTHING;"
else
"INSERT IGNORE INTO #{table_columns_and_values};"
@@ -101,6 +106,15 @@ module Gitlab
ActiveRecord::Base.connection.execute(sql)
end
+ def postgresql?
+ @postgresql ||= Gitlab::Database.postgresql?
+ end
+
+ def postgresql_pre_9_5?
+ @postgresql_pre_9_5 ||= postgresql? &&
+ ActiveRecord::Base.connection.select_value('SHOW server_version_num').to_i < 90500
+ end
+
def schedule_populate_untracked_uploads_jobs
bulk_queue_background_migration_jobs_by_range(UntrackedFile, FOLLOW_UP_MIGRATION)
end