diff options
author | Michael Kozono <mkozono@gmail.com> | 2017-11-15 15:51:28 +0300 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2017-12-02 02:26:41 +0300 |
commit | 10c660be007406533e48d5e3c6485ecf210e051b (patch) | |
tree | af25d0a5a84c6f1f79993422e824e1e11235fc65 | |
parent | 7fd26434196df01091b18747f91f54c0701bb292 (diff) |
Fix migration for pre-Postgres 9.5
-rw-r--r-- | lib/gitlab/background_migration/prepare_untracked_uploads.rb | 16 |
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 |