diff options
Diffstat (limited to 'db/post_migrate/20180430161409_migrate_legacy_artifacts_to_job_artifacts.rb')
-rw-r--r-- | db/post_migrate/20180430161409_migrate_legacy_artifacts_to_job_artifacts.rb | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/db/post_migrate/20180430161409_migrate_legacy_artifacts_to_job_artifacts.rb b/db/post_migrate/20180430161409_migrate_legacy_artifacts_to_job_artifacts.rb index 26330eff48c..01f67e48de1 100644 --- a/db/post_migrate/20180430161409_migrate_legacy_artifacts_to_job_artifacts.rb +++ b/db/post_migrate/20180430161409_migrate_legacy_artifacts_to_job_artifacts.rb @@ -8,19 +8,32 @@ class MigrateLegacyArtifactsToJobArtifacts < ActiveRecord::Migration disable_ddl_transaction! + class Build < ActiveRecord::Base + include EachBatch + + self.table_name = 'ci_builds' + self.inheritance_column = :_type_disabled + + scope :with_legacy_artifacts, -> { where("artifacts_file <> ''") } + + scope :without_new_artifacts, -> 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 = 1)') + end + end + def up ## - # We add a temporary index to `artifacts_file`. If we don't have the index, - # the first query (`SELECT .. WHERE .. ORDER BY id ASC LIMIT 1``) of `each_batch` will likely fail by statement timeout. + # We add a temporary index to the `ci_builds.artifacts_file` column. + # Without the index, the first query (`SELECT .. WHERE .. ORDER BY id ASC LIMIT 1``) of `each_batch` will likely fail by statement timeout. # The following querires which will be executed in backgroun migrartions are fine without the index, - # because it's scanned by using `BETWEEN` clause (e.g. 'id BETWEEN 0 AND 2000') at the first place. + # because it's scanned by using `BETWEEN` clause (e.g. 'id BETWEEN 0 AND 2000') at the beginning and narrow down target rows. unless index_exists_by_name?(:ci_builds, TMP_INDEX) if Gitlab::Database.postgresql? add_concurrent_index :ci_builds, :artifacts_file, where: "artifacts_file <> ''", name: TMP_INDEX end end - ::Gitlab::BackgroundMigration::MigrateLegacyArtifacts::Build + MigrateLegacyArtifactsToJobArtifacts::Build .with_legacy_artifacts.without_new_artifacts.tap do |relation| queue_background_migration_jobs_by_range_at_intervals(relation, MIGRATION, |