summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-07-03 19:11:15 +0900
committerShinya Maeda <shinya@gitlab.com>2018-07-03 19:11:15 +0900
commit6527620f9d0ffa769ac552e230ace322c24ca720 (patch)
treee33fe4a417d3f2a71392ca753809a3e5086b4984
parent275fbf24b1810e2fbef92b6599d5372855b97b46 (diff)
downloadgitlab-ce-add-background-migration-for-filling-file-location-ci-job-artifacts.tar.gz
Add post migrations to fill nullified file_locationadd-background-migration-for-filling-file-location-ci-job-artifacts
-rw-r--r--db/post_migrate/20180702135109_fill_file_location_to_job_artifacts.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/db/post_migrate/20180702135109_fill_file_location_to_job_artifacts.rb b/db/post_migrate/20180702135109_fill_file_location_to_job_artifacts.rb
new file mode 100644
index 00000000000..2bfd3e029f3
--- /dev/null
+++ b/db/post_migrate/20180702135109_fill_file_location_to_job_artifacts.rb
@@ -0,0 +1,33 @@
+class FillFileLocationToJobArtifacts < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ BATCH_SIZE = 10_000
+ TMP_INDEX = 'tmp_index_ci_job_artifacts_on_id_with_null_file_location'.freeze
+ CI_JOB_ARTIFACT_FILE_LOCATION_HASHED_PATH = 2 # Equavalant to Ci::JobArtifact.file_locations[:hashed_path]
+
+ disable_ddl_transaction!
+
+ class JobArtifact < ActiveRecord::Base
+ include EachBatch
+ self.table_name = 'ci_job_artifacts'
+ end
+
+ def up
+ unless index_exists_by_name?(:ci_job_artifacts, TMP_INDEX)
+ # This partial index is to be removed after the clean-up phase of the background migrations for legacy artifacts.
+ add_concurrent_index(:ci_job_artifacts, :id, where: 'file_location is NULL', name: TMP_INDEX)
+ end
+
+ # TODO: Use background migrations?
+ FillFileLocationToJobArtifacts::JobArtifact.where(file_location: nil).each_batch(of: BATCH_SIZE) do |relation|
+ relation.update_all(file_location: CI_JOB_ARTIFACT_FILE_LOCATION_HASHED_PATH)
+ end
+ end
+
+ def down
+ if index_exists_by_name?(:ci_job_artifacts, TMP_INDEX)
+ remove_concurrent_index_by_name(:ci_job_artifacts, TMP_INDEX)
+ end
+ end
+end