summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-04-24 16:43:19 +0900
committerShinya Maeda <shinya@gitlab.com>2018-05-28 14:50:10 +0900
commit76f0d7fe6e1a80d5b07eaa792f33d62ec8736d0d (patch)
tree186faf53a61cbdf0cd4af943c782ccf3f6c44eb5 /db
parent014f5f6a69f63ee42bd94454108268f189b62b18 (diff)
downloadgitlab-ce-76f0d7fe6e1a80d5b07eaa792f33d62ec8736d0d.tar.gz
Add background migration to fill file stores
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20180424151928_fill_file_store.rb.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/db/post_migrate/20180424151928_fill_file_store.rb.rb b/db/post_migrate/20180424151928_fill_file_store.rb.rb
new file mode 100644
index 00000000000..ecf169a4953
--- /dev/null
+++ b/db/post_migrate/20180424151928_fill_file_store.rb.rb
@@ -0,0 +1,95 @@
+class FillFileStore < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ class Build < ActiveRecord::Base
+ include EachBatch
+ self.table_name = 'ci_builds'
+ BATCH_SIZE = 10_000
+
+ def self.queue_background_migration
+ self.class.where(artifacts_file_store: nil).tap do |relation|
+ queue_background_migration_jobs_by_range_at_intervals(relation,
+ 'FillFileStoreBuildArchive',
+ 5.minutes,
+ batch_size: BATCH_SIZE)
+ end
+
+ self.class.where(artifacts_metadata_store: nil).tap do |relation|
+ queue_background_migration_jobs_by_range_at_intervals(relation,
+ 'FillFileStoreBuildMetadata',
+ 5.minutes,
+ batch_size: BATCH_SIZE)
+ end
+ end
+ end
+
+ class JobArtifact < ActiveRecord::Base
+ include EachBatch
+ self.table_name = 'ci_job_artifacts'
+ BATCH_SIZE = 10_000
+
+ def self.queue_background_migration
+ self.class.where(file_store: nil).tap do |relation|
+ queue_background_migration_jobs_by_range_at_intervals(relation,
+ 'FillFileStoreJobArtifact',
+ 5.minutes,
+ batch_size: BATCH_SIZE)
+ end
+ end
+ end
+
+ class LfsObject < ActiveRecord::Base
+ include EachBatch
+ self.table_name = 'lfs_objects'
+ BATCH_SIZE = 10_000
+
+ def self.queue_background_migration
+ self.class.where(file_store: nil).tap do |relation|
+ queue_background_migration_jobs_by_range_at_intervals(relation,
+ 'FillFileStoreLfsObject',
+ 5.minutes,
+ batch_size: BATCH_SIZE)
+ end
+ end
+ end
+
+ class Upload < ActiveRecord::Base
+ include EachBatch
+ self.table_name = 'uploads'
+ BATCH_SIZE = 10_000
+
+ def self.queue_background_migration
+ self.class.where(store: nil).tap do |relation|
+ queue_background_migration_jobs_by_range_at_intervals(relation,
+ 'FillFileStoreUpload',
+ 5.minutes,
+ batch_size: BATCH_SIZE)
+ end
+ end
+ end
+
+ def up
+ disable_statement_timeout
+
+ # Schedule background migrations that fill 'NULL' value by '1' on `file_store`, `store`, `artifacts_file_store` columns
+ # '1' represents ObjectStorage::Store::LOCAL
+ # ci_builds.artifacts_file_store
+ # ci_builds.artifacts_metadata_store
+ # ci_job_artifacts.file_store
+ # lfs_objects.file_store
+ # uploads.store
+
+ FillFileStore::Build.queue_background_migration
+ FillFileStore::JobArtifact.queue_background_migration
+ FillFileStore::LfsObject.queue_background_migration
+ FillFileStore::Upload.queue_background_migration
+ end
+
+ def down
+ # noop
+ end
+end