Commit a740edfe authored by pbair's avatar pbair

Use replace table helper in partitioning tests

Update the partitioning migration tests to also verify that the oid of
the original and replacement tables update as expected, which guarantees
that the tables swapped correctly.
parent 1471ed0b
...@@ -65,14 +65,7 @@ RSpec.describe Gitlab::Database::Partitioning::ReplaceTable, '#perform' do ...@@ -65,14 +65,7 @@ RSpec.describe Gitlab::Database::Partitioning::ReplaceTable, '#perform' do
expect(primary_key_constraint_name(archived_table)).to eq(archived_primary_key) expect(primary_key_constraint_name(archived_table)).to eq(archived_primary_key)
end end
def expect_table_to_be_replaced def expect_table_to_be_replaced(&block)
original_id = table_oid(original_table) super(original_table: original_table, replacement_table: replacement_table, archived_table: archived_table, &block)
replacement_id = table_oid(replacement_table)
yield
expect(table_oid(original_table)).to eq(replacement_id)
expect(table_oid(archived_table)).to eq(original_id)
expect(table_oid(replacement_table)).to be_nil
end end
end end
...@@ -642,7 +642,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe ...@@ -642,7 +642,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe
expect(table_type(partitioned_table)).to eq('partitioned') expect(table_type(partitioned_table)).to eq('partitioned')
expect(table_type(archived_table)).to be_nil expect(table_type(archived_table)).to be_nil
migration.replace_with_partitioned_table source_table expect_table_to_be_replaced { migration.replace_with_partitioned_table(source_table) }
expect(table_type(source_table)).to eq('partitioned') expect(table_type(source_table)).to eq('partitioned')
expect(table_type(archived_table)).to eq('normal') expect(table_type(archived_table)).to eq('normal')
...@@ -653,11 +653,15 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe ...@@ -653,11 +653,15 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe
expect_function_to_exist(function_name) expect_function_to_exist(function_name)
expect_valid_function_trigger(source_table, trigger_name, function_name, after: %w[delete insert update]) expect_valid_function_trigger(source_table, trigger_name, function_name, after: %w[delete insert update])
migration.replace_with_partitioned_table source_table expect_table_to_be_replaced { migration.replace_with_partitioned_table(source_table) }
expect_function_to_exist(function_name) expect_function_to_exist(function_name)
expect_valid_function_trigger(source_table, trigger_name, function_name, after: %w[delete insert update]) expect_valid_function_trigger(source_table, trigger_name, function_name, after: %w[delete insert update])
end end
def expect_table_to_be_replaced(&block)
super(original_table: source_table, replacement_table: partitioned_table, archived_table: archived_table, &block)
end
end end
describe '#rollback_replace_with_partitioned_table' do describe '#rollback_replace_with_partitioned_table' do
...@@ -674,7 +678,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe ...@@ -674,7 +678,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe
expect(table_type(archived_table)).to eq('normal') expect(table_type(archived_table)).to eq('normal')
expect(table_type(partitioned_table)).to be_nil expect(table_type(partitioned_table)).to be_nil
migration.rollback_replace_with_partitioned_table source_table expect_table_to_be_replaced { migration.rollback_replace_with_partitioned_table(source_table) }
expect(table_type(source_table)).to eq('normal') expect(table_type(source_table)).to eq('normal')
expect(table_type(partitioned_table)).to eq('partitioned') expect(table_type(partitioned_table)).to eq('partitioned')
...@@ -685,11 +689,15 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe ...@@ -685,11 +689,15 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe
expect_function_to_exist(function_name) expect_function_to_exist(function_name)
expect_valid_function_trigger(source_table, trigger_name, function_name, after: %w[delete insert update]) expect_valid_function_trigger(source_table, trigger_name, function_name, after: %w[delete insert update])
migration.rollback_replace_with_partitioned_table source_table expect_table_to_be_replaced { migration.rollback_replace_with_partitioned_table(source_table) }
expect_function_to_exist(function_name) expect_function_to_exist(function_name)
expect_valid_function_trigger(source_table, trigger_name, function_name, after: %w[delete insert update]) expect_valid_function_trigger(source_table, trigger_name, function_name, after: %w[delete insert update])
end end
def expect_table_to_be_replaced(&block)
super(original_table: source_table, replacement_table: archived_table, archived_table: partitioned_table, &block)
end
end end
def filter_columns_by_name(columns, names) def filter_columns_by_name(columns, names)
......
...@@ -5,6 +5,17 @@ module TableSchemaHelpers ...@@ -5,6 +5,17 @@ module TableSchemaHelpers
ActiveRecord::Base.connection ActiveRecord::Base.connection
end end
def expect_table_to_be_replaced(original_table:, replacement_table:, archived_table:)
original_oid = table_oid(original_table)
replacement_oid = table_oid(replacement_table)
yield
expect(table_oid(original_table)).to eq(replacement_oid)
expect(table_oid(archived_table)).to eq(original_oid)
expect(table_oid(replacement_table)).to be_nil
end
def table_oid(name) def table_oid(name)
connection.select_value(<<~SQL) connection.select_value(<<~SQL)
SELECT oid SELECT oid
......
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