-
Notifications
You must be signed in to change notification settings - Fork 317
feat: add schema qualification hints for extension type errors #4513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
@sweatybridge can you confirm if adding extensions to the search_path after each RESET ALL is the right approach to keep types like ltree accessible during migrations? Just want to make sure this aligns with expected behavior before taking the PR out of draft. If you have any suggestions, I’m happy to adjust. |
|
Thanks for checking. Our current recommendation is to always use schema qualified references in your migration file. For eg. CREATE TABLE test (path extensions.ltree NOT NULL);This avoids ambiguity in default search path resolution which can be configured per session, per role, or per cluster. The default search path for Supabase postgres role is currently set to |
@sweatybridge Thanks for the elaboration! I get that relying on a fixed search_path isn’t future-proof. |
Do you plan to do this by inspecting the error object returned from pgx? If so, that sounds good to me. Thanks for your help. |
Yep, I’ll inspect the pgx error and add the clearer message + schema qualification hint. On it |
b68f5bb to
1b972d2
Compare
Pull Request Test Coverage Report for Build 19741472306Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Inspect pgx errors for SQLSTATE 42704 (undefined_object) and provide helpful hints when extension types are not found. The error message now: - Detects 'type does not exist' errors - Extracts the type name from the error message - Suggests using schema-qualified references (e.g., extensions.ltree) - Provides a concrete example in the error output This addresses the issue where migrations work locally but fail remotely with opaque 'type does not exist' errors, making it clear to users that they should use schema-qualified type references instead of relying on search_path settings.
1b972d2 to
711463f
Compare
|
@sweatybridge whenever you have a moment, a quick review would be appreciated. 💚 |
sweatybridge
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nitpicks
Co-authored-by: Han Qiao <sweatybridge@gmail.com>
|
@sweatybridge All requested changes have been applied. Ready for rereview. 💚 |
Problem
When using extensions like
ltreein theextensionsschema, migrations can fail with cryptic errors:ERROR: type "ltree" does not exist (SQLSTATE 42704)
This error is confusing because:
search_pathsettingsSolution
Improve the CLI error message by inspecting the
pgconn.PgErrorobject and providing a helpful hint when extension types are not found.When SQLSTATE 42704 (
undefined_object) is returned for a missing type, the CLI now displays:Hint: This type may be defined in a schema that's not in your search_path. Use schema-qualified type references to avoid this error: CREATE TABLE example (col extensions.ltree); Learn more: supabase migration new --help
Changes
pkg/migration/file.goto detect extension type errors via pgx error inspectionextractTypeName()helper to parse type name from error messageextensions.ltree)Testing
pgconn.PgError.Codefor SQLSTATE 42704Related
Addresses feedback from supabase/supabase#40781