diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-03 18:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-03 18:09:24 +0300 |
commit | 6cbb93596d65dff377372f4b50da932dcf6dc514 (patch) | |
tree | c381ee98bd0fb444665f11c452b8e8f0e8e7731a /db | |
parent | ce9b8ee20d039da5f93e37d0ab3905813f3dd7bc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20210115220610_schedule_artifact_expiry_backfill.rb | 48 | ||||
-rw-r--r-- | db/schema_migrations/20210115220610 | 1 | ||||
-rw-r--r-- | db/structure.sql | 4 |
3 files changed, 51 insertions, 2 deletions
diff --git a/db/post_migrate/20210115220610_schedule_artifact_expiry_backfill.rb b/db/post_migrate/20210115220610_schedule_artifact_expiry_backfill.rb new file mode 100644 index 00000000000..44a76321495 --- /dev/null +++ b/db/post_migrate/20210115220610_schedule_artifact_expiry_backfill.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class ScheduleArtifactExpiryBackfill < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + MIGRATION = 'BackfillArtifactExpiryDate'.freeze + SWITCH_DATE = Date.new(2020, 06, 22).freeze + INDEX_NAME = 'expired_artifacts_temp_index'.freeze + OLD_INDEX_CONDITION = "expire_at IS NULL AND created_at < '#{SWITCH_DATE}'" + INDEX_CONDITION = "expire_at IS NULL AND date(created_at AT TIME ZONE 'UTC') < '2020-06-22'::date".freeze + + disable_ddl_transaction! + + class JobArtifact < ActiveRecord::Base + include EachBatch + + 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 + # Create temporary index for expired artifacts + # Needs to be removed in a later migration + remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME + add_concurrent_index(:ci_job_artifacts, %i(id created_at), where: INDEX_CONDITION, name: INDEX_NAME) + + queue_background_migration_jobs_by_range_at_intervals( + JobArtifact.without_expiry_date.before_switch, + MIGRATION, + 2.minutes, + batch_size: 200_000 + ) + end + + def down + remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME + add_concurrent_index(:ci_job_artifacts, %i(id created_at), where: OLD_INDEX_CONDITION, name: INDEX_NAME) + + Gitlab::BackgroundMigration.steal(MIGRATION) do |job| + job.delete + + false + end + end +end diff --git a/db/schema_migrations/20210115220610 b/db/schema_migrations/20210115220610 new file mode 100644 index 00000000000..002c37e54ec --- /dev/null +++ b/db/schema_migrations/20210115220610 @@ -0,0 +1 @@ +541a6626d3afd4fd421fd59fe5eb8ab7764952ae780c83c3805fd4a29e3f42fb
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index a0a93a749fd..00ec06d7d6f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -22,8 +22,8 @@ UPDATE projects SET has_external_issue_tracker = ( WHERE project_id = COALESCE(NEW.project_id, OLD.project_id) AND active = TRUE AND category = 'issue_tracker' - ) ) +) WHERE projects.id = COALESCE(NEW.project_id, OLD.project_id); RETURN NULL; @@ -21047,7 +21047,7 @@ CREATE UNIQUE INDEX epic_user_mentions_on_epic_id_and_note_id_index ON epic_user CREATE UNIQUE INDEX epic_user_mentions_on_epic_id_index ON epic_user_mentions USING btree (epic_id) WHERE (note_id IS NULL); -CREATE INDEX expired_artifacts_temp_index ON ci_job_artifacts USING btree (id, created_at) WHERE ((expire_at IS NULL) AND (created_at < '2020-06-22 00:00:00+00'::timestamp with time zone)); +CREATE INDEX expired_artifacts_temp_index ON ci_job_artifacts USING btree (id, created_at) WHERE ((expire_at IS NULL) AND (date(timezone('UTC'::text, created_at)) < '2020-06-22'::date)); CREATE INDEX finding_links_on_vulnerability_occurrence_id ON vulnerability_finding_links USING btree (vulnerability_occurrence_id); |