2018-05-29 04:06:14 -04:00
|
|
|
class ArchiveLegacyTraces < ActiveRecord::Migration
|
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
2018-06-03 01:21:50 -04:00
|
|
|
BATCH_SIZE = 5000
|
2018-05-29 04:06:14 -04:00
|
|
|
BACKGROUND_MIGRATION_CLASS = 'ArchiveLegacyTraces'
|
|
|
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
class Build < ActiveRecord::Base
|
|
|
|
include EachBatch
|
|
|
|
self.table_name = 'ci_builds'
|
|
|
|
self.inheritance_column = :_type_disabled # Disable STI
|
|
|
|
|
|
|
|
scope :finished, -> { where(status: [:success, :failed, :canceled]) }
|
|
|
|
|
2018-06-03 01:21:50 -04:00
|
|
|
scope :without_archived_trace, -> do
|
|
|
|
where('NOT EXISTS (SELECT 1 FROM ci_job_artifacts WHERE ci_builds.id = ci_job_artifacts.job_id AND ci_job_artifacts.file_type = 3)')
|
2018-05-29 04:06:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def up
|
|
|
|
queue_background_migration_jobs_by_range_at_intervals(
|
2018-06-03 01:21:50 -04:00
|
|
|
::ArchiveLegacyTraces::Build.finished.without_archived_trace,
|
2018-05-29 04:06:14 -04:00
|
|
|
BACKGROUND_MIGRATION_CLASS,
|
|
|
|
5.minutes,
|
|
|
|
batch_size: BATCH_SIZE)
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# noop
|
|
|
|
end
|
|
|
|
end
|