Skip to content
代码片段 群组 项目
提交 6a6c3f78 编辑于 作者: Dylan Griffith's avatar Dylan Griffith
浏览文件

Use correct gitlab_schema in gitlab-housekeeper finalize BG migration

Previously we were determining the gitlab_schema from the `table_name`.
This is causing problems as we're migrating lots of tables to
`gitlab_main_cell`. But the `gitlab_schema` must exactly match whatever
schema was used to queue the batched background migration (see
https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#finalize-a-batched-background-migration
) . As such we've extracted this value from the migration record in the
database which should always be the expected value.
上级 33ece4d3
No related branches found
No related tags found
无相关合并请求
...@@ -11,7 +11,7 @@ def initialize ...@@ -11,7 +11,7 @@ def initialize
def fetch_background_migration_status(job_class_name) def fetch_background_migration_status(job_class_name)
query = <<~SQL query = <<~SQL
SELECT id, created_at, updated_at, finished_at, started_at, status, job_class_name SELECT id, created_at, updated_at, finished_at, started_at, status, job_class_name, gitlab_schema
FROM batched_background_migrations FROM batched_background_migrations
WHERE job_class_name = $1::text WHERE job_class_name = $1::text
SQL SQL
......
...@@ -81,7 +81,7 @@ def each_change ...@@ -81,7 +81,7 @@ def each_change
migration_file = generator.invoke_all.first migration_file = generator.invoke_all.first
change.changed_files = [migration_file] change.changed_files = [migration_file]
add_ensure_call_to_migration(migration_file, queue_method_node, job_name) add_ensure_call_to_migration(migration_file, queue_method_node, job_name, migration_record)
::Gitlab::Housekeeper::Shell.execute('rubocop', '-a', migration_file) ::Gitlab::Housekeeper::Shell.execute('rubocop', '-a', migration_file)
digest = Digest::SHA256.hexdigest(generator.migration_number) digest = Digest::SHA256.hexdigest(generator.migration_number)
...@@ -126,7 +126,7 @@ def last_migration_for_job(job_name) ...@@ -126,7 +126,7 @@ def last_migration_for_job(job_name)
nil nil
end end
def add_ensure_call_to_migration(file, queue_method_node, job_name) def add_ensure_call_to_migration(file, queue_method_node, job_name, migration_record)
source = RuboCop::ProcessedSource.new(File.read(file), 3.1) source = RuboCop::ProcessedSource.new(File.read(file), 3.1)
ast = source.ast ast = source.ast
source_buffer = source.buffer source_buffer = source.buffer
...@@ -140,7 +140,7 @@ def add_ensure_call_to_migration(file, queue_method_node, job_name) ...@@ -140,7 +140,7 @@ def add_ensure_call_to_migration(file, queue_method_node, job_name)
column_name = queue_method_node.children[4] column_name = queue_method_node.children[4]
job_arguments = queue_method_node.children[5..].select { |s| s.type != :hash } # All remaining non-keyword args job_arguments = queue_method_node.children[5..].select { |s| s.type != :hash } # All remaining non-keyword args
gitlab_schema = ::Gitlab::Database::GitlabSchema.table_schema(table_name.value.to_s) gitlab_schema = migration_record.gitlab_schema
added_content = <<~RUBY.strip added_content = <<~RUBY.strip
disable_ddl_transaction! disable_ddl_transaction!
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
let(:job_class_name) { 'ExampleJob' } let(:job_class_name) { 'ExampleJob' }
let(:query) do let(:query) do
<<~SQL <<~SQL
SELECT id, created_at, updated_at, finished_at, started_at, status, job_class_name SELECT id, created_at, updated_at, finished_at, started_at, status, job_class_name, gitlab_schema
FROM batched_background_migrations FROM batched_background_migrations
WHERE job_class_name = $1::text WHERE job_class_name = $1::text
SQL SQL
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册