diff --git a/scripts/attach-schema-partitions.sql b/scripts/attach-schema-partitions.sql index de9e94011..478eab1ff 100644 --- a/scripts/attach-schema-partitions.sql +++ b/scripts/attach-schema-partitions.sql @@ -81,11 +81,19 @@ BEGIN FOR VALUES FROM ('2026-07-01') TO (MAXVALUE); END IF; + -- When pgschema creates partition children as standalone tables, it also + -- preserves the parent's identity column on delivery_log children. PostgreSQL + -- rejects attaching a child table that has its own identity column, so each + -- delivery_log attach path drops that standalone identity first. Raw + -- schema-created partitions are already attached, so these branches do not + -- run against inherited partition columns. + IF NOT EXISTS ( SELECT 1 FROM pg_inherits WHERE inhparent = 'delivery_log'::regclass AND inhrelid = 'delivery_log_p_past'::regclass ) THEN + ALTER TABLE delivery_log_p_past ALTER COLUMN id DROP IDENTITY IF EXISTS; ALTER TABLE delivery_log ATTACH PARTITION delivery_log_p_past FOR VALUES FROM (MINVALUE) TO ('2026-03-01'); END IF; @@ -95,6 +103,7 @@ BEGIN WHERE inhparent = 'delivery_log'::regclass AND inhrelid = 'delivery_log_p2026_03'::regclass ) THEN + ALTER TABLE delivery_log_p2026_03 ALTER COLUMN id DROP IDENTITY IF EXISTS; ALTER TABLE delivery_log ATTACH PARTITION delivery_log_p2026_03 FOR VALUES FROM ('2026-03-01') TO ('2026-04-01'); END IF; @@ -104,6 +113,7 @@ BEGIN WHERE inhparent = 'delivery_log'::regclass AND inhrelid = 'delivery_log_p2026_04'::regclass ) THEN + ALTER TABLE delivery_log_p2026_04 ALTER COLUMN id DROP IDENTITY IF EXISTS; ALTER TABLE delivery_log ATTACH PARTITION delivery_log_p2026_04 FOR VALUES FROM ('2026-04-01') TO ('2026-05-01'); END IF; @@ -113,6 +123,7 @@ BEGIN WHERE inhparent = 'delivery_log'::regclass AND inhrelid = 'delivery_log_p2026_05'::regclass ) THEN + ALTER TABLE delivery_log_p2026_05 ALTER COLUMN id DROP IDENTITY IF EXISTS; ALTER TABLE delivery_log ATTACH PARTITION delivery_log_p2026_05 FOR VALUES FROM ('2026-05-01') TO ('2026-06-01'); END IF; @@ -122,6 +133,7 @@ BEGIN WHERE inhparent = 'delivery_log'::regclass AND inhrelid = 'delivery_log_p2026_06'::regclass ) THEN + ALTER TABLE delivery_log_p2026_06 ALTER COLUMN id DROP IDENTITY IF EXISTS; ALTER TABLE delivery_log ATTACH PARTITION delivery_log_p2026_06 FOR VALUES FROM ('2026-06-01') TO ('2026-07-01'); END IF; @@ -131,6 +143,7 @@ BEGIN WHERE inhparent = 'delivery_log'::regclass AND inhrelid = 'delivery_log_p_future'::regclass ) THEN + ALTER TABLE delivery_log_p_future ALTER COLUMN id DROP IDENTITY IF EXISTS; ALTER TABLE delivery_log ATTACH PARTITION delivery_log_p_future FOR VALUES FROM ('2026-07-01') TO (MAXVALUE); END IF;