Commit 79a95be4 authored by Andreas Brandl's avatar Andreas Brandl

Atomically create table and its partitions

This is to avoid a race condition when we succeed to create the
partitioned table but failed to create its partitions.

In that case, automatic partition management might kick in leading to
undesired states.

We basically want the migration to fully succeed first, before
partitions are being automatically managed.

Relates to https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/5597
parent 29ac2713
......@@ -62,8 +62,10 @@ module Gitlab
partitioned_table_name = make_partitioned_table_name(table_name)
create_range_partitioned_copy(table_name, partitioned_table_name, partition_column, primary_key)
create_daterange_partitions(partitioned_table_name, partition_column.name, min_date, max_date)
transaction do
create_range_partitioned_copy(table_name, partitioned_table_name, partition_column, primary_key)
create_daterange_partitions(partitioned_table_name, partition_column.name, min_date, max_date)
end
create_trigger_to_sync_tables(table_name, partitioned_table_name, primary_key)
end
......
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