Skip to content

feat: Add PostgreSQL Extension Support#5

Merged
NFUChen merged 2 commits into
mainfrom
feat/extension-detection
May 16, 2026
Merged

feat: Add PostgreSQL Extension Support#5
NFUChen merged 2 commits into
mainfrom
feat/extension-detection

Conversation

@NFUChen
Copy link
Copy Markdown
Owner

@NFUChen NFUChen commented May 16, 2026

Summary

  • Automatically detect extensions required by schema objects (e.g., btree_gist for EXCLUDE constraints, citext/hstore for column types) by querying pg_depend catalog dependencies
  • Generate CREATE EXTENSION IF NOT EXISTS statements in migration output, ordered before all schema objects to satisfy dependencies
  • Support extension diffing (add/drop detection) between old and new schemas

Changes

IR Layer

  • ir/ir.go: Added Extensions []string field to IR struct and new Extension struct implementing DiffSource
  • ir/inspector.go: New buildExtensions() method that queries pg_catalog.pg_depend to find extensions used by constraints, classes, types, and functions in the target schema (excludes plpgsql and extension-internal objects)

Diff Layer

  • internal/diff/diff.go: New DiffTypeExtension, extension comparison logic in GenerateMigration(), and CREATE EXTENSION IF NOT EXISTS DDL generation at the top of generateCreateSQL()

Plan & Dump

  • internal/plan/schema_plan.go: Added TypeExtension to object ordering (first in dependency order)
  • internal/dump/formatter.go: Added extensions directory to multi-file output and mapping for extension type

Tests

  • ir/inspector_extension_test.go: Tests that empty schemas don't detect extensions, and schemas with EXCLUDE constraints correctly detect btree_gist
  • testdata/diff/dependency/extension_btree_gist/: New test fixture for btree_gist extension with EXCLUDE USING gist constraint
  • Updated fixtures: add_pk, add_column_cross_schema_custom_type to include expected extension output

@NFUChen NFUChen changed the title feat: implement extension detection and management in schema diff feat: Add PostgreSQL Extension Support May 16, 2026
@NFUChen NFUChen merged commit 8c07a92 into main May 16, 2026
1 check 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.

2 participants