Skip to content

Conversation

@tianzhou
Copy link
Contributor

@tianzhou tianzhou commented Dec 18, 2025

Fix #197

When applying SQL to temporary schemas, extension types installed in the public schema (e.g., citext) failed to resolve because the search_path only included the temp schema.

Changes:

  • Add public to search_path in embedded.go, external.go, and testutil
  • Add ParseSQLToIRWithSetup() for tests needing setup SQL after schema reset
  • Update test case to reproduce the bug with citext in public schema
  • Make setup.sql files idempotent for repeated execution
  • Add stripSchemaPrefix in generating type statement

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings December 18, 2025 08:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #197 where extension types installed in the public schema (e.g., citext) failed to resolve when applying SQL to temporary schemas because the search_path only included the temp schema.

Key changes:

  • Modified search_path in all schema application code to include both the target schema and public as a fallback
  • Added ParseSQLToIRWithSetup() function to execute setup SQL after schema recreation but before main SQL
  • Updated test infrastructure to make setup.sql files idempotent and demonstrate the fix with citext extension

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
testutil/postgres.go Added ParseSQLToIRWithSetup() helper and updated search_path to include public schema for extension type resolution
internal/postgres/external.go Updated search_path in production code to include public schema as fallback for extension types
internal/postgres/embedded.go Updated search_path in embedded postgres to include public schema as fallback for extension types
internal/diff/diff_test.go Refactored to use ParseSQLToIRWithSetup() instead of executing setup.sql before schema recreation
testdata/diff/create_table/add_column_cross_schema_custom_type/setup.sql Made setup idempotent with DROP/CREATE and moved citext to public schema to reproduce issue #197
testdata/diff/create_table/add_column_cross_schema_custom_type/new.sql Updated test to use unqualified citext type in public schema demonstrating natural usage pattern
testdata/diff/create_table/add_column_cross_schema_custom_type/plan.txt Updated expected output to reflect citext being unqualified in public schema
testdata/diff/create_table/add_column_cross_schema_custom_type/plan.sql Updated expected migration SQL with correct type qualification
testdata/diff/create_table/add_column_cross_schema_custom_type/diff.sql Updated expected diff output with correct type qualification
testdata/diff/create_function/alter_function_same_signature/setup.sql Made setup idempotent with DROP/CREATE for consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

When applying SQL to temporary schemas, extension types installed in
the public schema (e.g., citext) failed to resolve because the
search_path only included the temp schema.

Changes:
- Add public to search_path in embedded.go, external.go, and testutil
- Add ParseSQLToIRWithSetup() for tests needing setup SQL after schema reset
- Fix type comparison to normalize schema prefix before comparing
- Fix ADD COLUMN and ALTER COLUMN TYPE to properly unqualify types
- Update test case to reproduce the bug with citext in public schema
- Make setup.sql files idempotent for repeated execution

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tianzhou tianzhou merged commit aa2b8fc into main Dec 18, 2025
8 checks passed
@tianzhou tianzhou deleted the extension_schema branch January 5, 2026 14:12
alecthomas pushed a commit to alecthomas/pgschema that referenced this pull request Jan 26, 2026
…lex#197) (pgplex#208)

When applying SQL to temporary schemas, extension types installed in
the public schema (e.g., citext) failed to resolve because the
search_path only included the temp schema.

Changes:
- Add public to search_path in embedded.go, external.go, and testutil
- Add ParseSQLToIRWithSetup() for tests needing setup SQL after schema reset
- Fix type comparison to normalize schema prefix before comparing
- Fix ADD COLUMN and ALTER COLUMN TYPE to properly unqualify types
- Update test case to reproduce the bug with citext in public schema
- Make setup.sql files idempotent for repeated execution

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
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.

when dumped references to objects installed from an extension are not fully qualified

1 participant