Repository navigation
fix: preserve extension schema qualifiers in dump and plan (#725) - #730
Conversation
Co-Authored-By: Tianzhou <t@bytebase.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
[Medium impact] The PR changes shared schema inspection used by several database workflows. Fix inherited defaults in cross-schema partition plans before merging. Findings
SummaryPreserves extension type and operator-class qualifiers in dumps and plans.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Target database] --> B[Inspect with catalog-only search path]
C[Desired SQL] --> D[Add partition parent stubs]
D --> E[Apply to planning database]
E --> F[Inspect desired schema]
F --> G[Normalize schema names]
G --> H[Restore real parents and remove stubs]
B --> I[Compare states]
H --> I
I --> J[Migration plan]
Reviews (1) · Last reviewed commit: "fix: preserve extension schema qualifier..." · Reviewed by Greptile |
| if stub := schema.Tables[table.PartitionOf]; stub != nil { | ||
| table.PartitionParentColumns = stub.Columns | ||
| } | ||
| table.PartitionOfSchema = parent.Schema | ||
| table.PartitionOf = parent.Table |
There was a problem hiding this comment.
Unchanged plans remove partition defaults
Cross-schema partitions with inherited defaults still produce changes when planning an unchanged dump. If public.events.x has DEFAULT 42 and archive.child is its partition, the dump correctly omits that matching default. But the planning stub has no defaults, so the replayed child has none either.
Restoring the parent name and copying stub.Columns does not restore the child's inherited default. The comparison then emits ALTER TABLE child ALTER COLUMN x DROP DEFAULT, changing later inserts directly into the partition. Preserve parent defaults when building the planning stub, and add an empty-plan test for this case.
Knowledge Base Used:
Co-Authored-By: Tianzhou <t@bytebase.com>
Co-Authored-By: Tianzhou <t@bytebase.com>
Co-Authored-By: Tianzhou <t@bytebase.com>
…lution Co-Authored-By: Tianzhou <t@bytebase.com>
Co-Authored-By: Tianzhou <t@bytebase.com>
Co-Authored-By: Tianzhou <t@bytebase.com>
Co-Authored-By: Tianzhou <t@bytebase.com>
Co-Authored-By: Tianzhou <t@bytebase.com>
Summary
Preserve operator-class namespaces such as
extensions.gin_trgm_ops. Deparse routine signatures, dependencies and privileges with only the routine schema onsearch_pathto preserve cross-schema extension types and match routine dependencies.Deparse SQL-standard routine bodies with their local schema visible for dumps so same-schema sequence references replay in the planning database. Compare parsed bodies with fully qualified references and remap those references to the target schema for migration SQL. Preserve whitespace inside parsed literals and use PostgreSQL's identifier quoting when remapping schema names.
Quote extension column types and preserve their qualification in partition-parent stubs. Restore the real cross-schema partition parent after inspection to keep planning-only tables out of migrations.
Regression tests cover dump and replay, routine drop order, and empty plans using
pg_trgmandhstoreon PostgreSQL 14 and 18 with embedded and external planning databases. A plan-onlyintarrayoperator retains its schema qualifier in migration SQL. Also verified dump and plan through a session-pooled PgBouncer 1.16.1 endpoint.Fixes #725
Link to Devin session: https://app.devin.ai/sessions/2160d3f08fd1454bb91db03645ac0427
Open in Devin Desktop: https://app.devin.ai/desktop/session/2160d3f08fd1454bb91db03645ac0427?variant=devin
Requested by: @tianzhou
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work