Commit ef1e8f46 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'fix_post_migrate_migrate_in' into 'master'

Fix migrate_in not working within a transaction

See merge request gitlab-org/gitlab!69631
parents 52f7c141 e11ba41a
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
class SliceMergeRequestDiffCommitMigrations < ActiveRecord::Migration[6.1] class SliceMergeRequestDiffCommitMigrations < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
BATCH_SIZE = 5_000 BATCH_SIZE = 5_000
MIGRATION_CLASS = 'MigrateMergeRequestDiffCommitUsers' MIGRATION_CLASS = 'MigrateMergeRequestDiffCommitUsers'
STEAL_MIGRATION_CLASS = 'StealMigrateMergeRequestDiffCommitUsers' STEAL_MIGRATION_CLASS = 'StealMigrateMergeRequestDiffCommitUsers'
...@@ -15,31 +17,33 @@ class SliceMergeRequestDiffCommitMigrations < ActiveRecord::Migration[6.1] ...@@ -15,31 +17,33 @@ class SliceMergeRequestDiffCommitMigrations < ActiveRecord::Migration[6.1]
return if old_jobs.empty? return if old_jobs.empty?
# This ensures we stop processing the old ranges, as the background transaction do
# migrations skip already processed jobs. # This ensures we stop processing the old ranges, as the background
Gitlab::Database::BackgroundMigrationJob # migrations skip already processed jobs.
.for_migration_class(MIGRATION_CLASS) Gitlab::Database::BackgroundMigrationJob
.pending .for_migration_class(MIGRATION_CLASS)
.update_all(status: :succeeded) .pending
.update_all(status: :succeeded)
rows = []
rows = []
old_jobs.each do |job|
min, max = job.arguments old_jobs.each do |job|
min, max = job.arguments
while min < max
rows << { while min < max
class_name: MIGRATION_CLASS, rows << {
arguments: [min, min + BATCH_SIZE], class_name: MIGRATION_CLASS,
created_at: Time.now.utc, arguments: [min, min + BATCH_SIZE],
updated_at: Time.now.utc created_at: Time.now.utc,
} updated_at: Time.now.utc
}
min += BATCH_SIZE
min += BATCH_SIZE
end
end end
end
Gitlab::Database::BackgroundMigrationJob.insert_all!(rows) Gitlab::Database::BackgroundMigrationJob.insert_all!(rows)
end
job = Gitlab::Database::BackgroundMigrationJob job = Gitlab::Database::BackgroundMigrationJob
.for_migration_class(MIGRATION_CLASS) .for_migration_class(MIGRATION_CLASS)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment