diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-05-29 17:06:14 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-06-04 14:14:20 +0900 |
commit | 89b4304f12cd37d8715c274cdee080e95f2d3bad (patch) | |
tree | 8172392264c1fe5a6d7d7bc3849506beaf982714 /db | |
parent | ee111285ece3857e29cb4181486a8392a54daaed (diff) | |
download | gitlab-ce-89b4304f12cd37d8715c274cdee080e95f2d3bad.tar.gz |
Add background migrations to arhive legacy traces
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20180529152628_archive_legacy_traces.rb | 44 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 45 insertions, 1 deletions
diff --git a/db/post_migrate/20180529152628_archive_legacy_traces.rb b/db/post_migrate/20180529152628_archive_legacy_traces.rb new file mode 100644 index 00000000000..78ec1ab1a94 --- /dev/null +++ b/db/post_migrate/20180529152628_archive_legacy_traces.rb @@ -0,0 +1,44 @@ +class ArchiveLegacyTraces < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 10_000 + 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]) } + + scope :without_new_traces, ->() do + where('NOT EXISTS (?)', + ::ArchiveLegacyTraces::JobArtifact.select(1).trace.where('ci_builds.id = ci_job_artifacts.job_id')) + end + end + + class JobArtifact < ActiveRecord::Base + self.table_name = 'ci_job_artifacts' + + enum file_type: { + archive: 1, + metadata: 2, + trace: 3 + } + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + ::ArchiveLegacyTraces::Build.finished.without_new_traces, + BACKGROUND_MIGRATION_CLASS, + 5.minutes, + batch_size: BATCH_SIZE) + end + + def down + # noop + end +end diff --git a/db/schema.rb b/db/schema.rb index 97247387bc7..a8f8e14a3fc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180529093006) do +ActiveRecord::Schema.define(version: 20180529152628) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |