0fc9f9d3e7
DB schema generated by a migration may look different in rails 4 and 5 (because rails 5 may use different default values). For this reason it's important to explicitly set for which rails version a migration was written for. See https://stackoverflow.com/questions/35929869/activerecordmigration-deprecation-warning-asks-for-rails-version-but-im-no/35930912#35930912
72 lines
2.1 KiB
Ruby
72 lines
2.1 KiB
Ruby
class FillFileStore < ActiveRecord::Migration[4.2]
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
DOWNTIME = false
|
|
|
|
disable_ddl_transaction!
|
|
|
|
class JobArtifact < ActiveRecord::Base
|
|
include EachBatch
|
|
self.table_name = 'ci_job_artifacts'
|
|
BATCH_SIZE = 10_000
|
|
|
|
def self.params_for_background_migration
|
|
yield self.where(file_store: nil), 'FillFileStoreJobArtifact', 5.minutes, BATCH_SIZE
|
|
end
|
|
end
|
|
|
|
class LfsObject < ActiveRecord::Base
|
|
include EachBatch
|
|
self.table_name = 'lfs_objects'
|
|
BATCH_SIZE = 10_000
|
|
|
|
def self.params_for_background_migration
|
|
yield self.where(file_store: nil), 'FillFileStoreLfsObject', 5.minutes, BATCH_SIZE
|
|
end
|
|
end
|
|
|
|
class Upload < ActiveRecord::Base
|
|
include EachBatch
|
|
self.table_name = 'uploads'
|
|
self.inheritance_column = :_type_disabled # Disable STI
|
|
BATCH_SIZE = 10_000
|
|
|
|
def self.params_for_background_migration
|
|
yield self.where(store: nil), 'FillStoreUpload', 5.minutes, BATCH_SIZE
|
|
end
|
|
end
|
|
|
|
def up
|
|
# NOTE: Schedule background migrations that fill 'NULL' value by '1'(ObjectStorage::Store::LOCAL) on `file_store`, `store` columns
|
|
#
|
|
# Here are the target columns
|
|
# - ci_job_artifacts.file_store
|
|
# - lfs_objects.file_store
|
|
# - uploads.store
|
|
|
|
FillFileStore::JobArtifact.params_for_background_migration do |relation, class_name, delay_interval, batch_size|
|
|
queue_background_migration_jobs_by_range_at_intervals(relation,
|
|
class_name,
|
|
delay_interval,
|
|
batch_size: batch_size)
|
|
end
|
|
|
|
FillFileStore::LfsObject.params_for_background_migration do |relation, class_name, delay_interval, batch_size|
|
|
queue_background_migration_jobs_by_range_at_intervals(relation,
|
|
class_name,
|
|
delay_interval,
|
|
batch_size: batch_size)
|
|
end
|
|
|
|
FillFileStore::Upload.params_for_background_migration do |relation, class_name, delay_interval, batch_size|
|
|
queue_background_migration_jobs_by_range_at_intervals(relation,
|
|
class_name,
|
|
delay_interval,
|
|
batch_size: batch_size)
|
|
end
|
|
end
|
|
|
|
def down
|
|
# noop
|
|
end
|
|
end
|