Skip to content

fix: preserve extension schema qualifiers in dump and plan (#725) - #730

Merged
tianzhou merged 9 commits into
mainfrom
devin/1795954139-issue-725-extension-qualifiers
Nov 30, 2026
Merged

tianzhou merged 9 commits into
mainfrom
devin/1795954139-issue-725-extension-qualifiers

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve operator-class namespaces such as extensions.gin_trgm_ops. Deparse routine signatures, dependencies and privileges with only the routine schema on search_path to 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_trgm and hstore on PostgreSQL 14 and 18 with embedded and external planning databases. A plan-only intarray operator 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

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · Fix inherited defaults in cross-schema partition plans before merging.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR changes shared schema inspection used by several database workflows.

Fix inherited defaults in cross-schema partition plans before merging.

Findings

  1. P1 Unchanged plans remove partition defaults ▶

Summary

Preserves extension type and operator-class qualifiers in dumps and plans.

  • Dumps keep extension types and index classes tied to their schemas.
  • Plans compare extension indexes and routine privileges using matching names.
  • Plans show cross-schema partitions with their real parent tables.

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]
Loading

Reviews (1) · Last reviewed commit: "fix: preserve extension schema qualifier..." · Reviewed by Greptile

Comment on lines +98 to +102
if stub := schema.Tables[table.PartitionOf]; stub != nil {
table.PartitionParentColumns = stub.Columns
}
table.PartitionOfSchema = parent.Schema
table.PartitionOf = parent.Table

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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>

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

devin-ai-integration Bot and others added 7 commits November 29, 2026 12:31
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>
@tianzhou
tianzhou merged commit 483f997 into main Nov 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dump strips schema qualification from extension operator classes (e.g. extensions.gin_trgm_ops), breaking subsequent plan

1 participant