diff --git a/lib/pg_ha_migrations/safe_statements.rb b/lib/pg_ha_migrations/safe_statements.rb index b13a1f7..23b20e6 100644 --- a/lib/pg_ha_migrations/safe_statements.rb +++ b/lib/pg_ha_migrations/safe_statements.rb @@ -199,8 +199,6 @@ def safe_add_concurrent_partitioned_index( return if if_not_exists && parent_index.valid? child_indexes = parent_table.partitions.map do |child_table| - raise PgHaMigrations::InvalidMigrationError, "Partitioned table #{parent_table.inspect} contains sub-partitions" if child_table.natively_partitioned? - PgHaMigrations::Index.from_table_and_columns(child_table, columns) end @@ -221,8 +219,14 @@ def safe_add_concurrent_partitioned_index( end child_indexes.each do |child_index| - # CREATE INDEX CONCURRENTLY ON child_table - safe_add_concurrent_index( + add_index_method = if child_index.table.natively_partitioned? + :safe_add_concurrent_partitioned_index + else + :safe_add_concurrent_index + end + + send( + add_index_method, child_index.table.fully_qualified_name, columns, name: child_index.name, diff --git a/spec/safe_statements_spec.rb b/spec/safe_statements_spec.rb index 0dc06b8..ce3d9cb 100644 --- a/spec/safe_statements_spec.rb +++ b/spec/safe_statements_spec.rb @@ -1732,33 +1732,6 @@ def up end.to raise_error(PgHaMigrations::InvalidMigrationError, "Table \"foos3\" is not a partitioned table") end - it "raises error when sub-partitioning detected" do - create_range_partitioned_table(:foos3, migration_klass) - create_range_partitioned_table(:foos3_sub, migration_klass) - - setup_migration = Class.new(migration_klass) do - def up - unsafe_execute(<<~SQL) - ALTER TABLE foos3 - ATTACH PARTITION foos3_sub - FOR VALUES FROM ('2020-01-01') TO ('2020-02-01') - SQL - end - end - - setup_migration.suppress_messages { setup_migration.migrate(:up) } - - test_migration = Class.new(migration_klass) do - def up - safe_add_concurrent_partitioned_index :foos3, :updated_at - end - end - - expect do - test_migration.suppress_messages { test_migration.migrate(:up) } - end.to raise_error(PgHaMigrations::InvalidMigrationError, "Partitioned table \"foos3\" contains sub-partitions") - end - it "raises error when index invalid" do create_range_partitioned_table(:foos3, migration_klass, with_partman: true)