diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb')
-rw-r--r-- | db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb b/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb new file mode 100644 index 00000000000..b4570c8398b --- /dev/null +++ b/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class RescheduleArtifactExpiryBackfillAgain < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + MIGRATION = 'BackfillArtifactExpiryDate' + SWITCH_DATE = Date.new(2020, 06, 22).freeze + + disable_ddl_transaction! + + class JobArtifact < ActiveRecord::Base + include EachBatch + + self.inheritance_column = :_type_disabled + self.table_name = 'ci_job_artifacts' + + scope :without_expiry_date, -> { where(expire_at: nil) } + scope :before_switch, -> { where("date(created_at AT TIME ZONE 'UTC') < ?::date", SWITCH_DATE) } + end + + def up + Gitlab::BackgroundMigration.steal(MIGRATION) do |job| + job.delete + + false + end + + queue_background_migration_jobs_by_range_at_intervals( + JobArtifact.without_expiry_date.before_switch, + MIGRATION, + 2.minutes, + batch_size: 200_000 + ) + end + + def down + Gitlab::BackgroundMigration.steal(MIGRATION) do |job| + job.delete + + false + end + end +end |