-
Notifications
You must be signed in to change notification settings - Fork 249
db diff
: Incorrect migration order for UDF used in CHECK constraint (Declarative Schema)
#3483
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
Comments
Tried also with
CRASH ID:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When using declarative schemas where a table's CHECK constraint depends on a User-Defined Function (UDF) defined in a separate, numerically earlier file (e.g.,
00_function.sql
and01_table.sql
), thesupabase db diff
command generates a migration file with incorrect statement ordering. The table definition appears before the required UDF definition, causing subsequent migration application to fail.To Reproduce
There is a repo that reproduces this bug at https://github.com/pgflow-dev/dbdiff-udf-check-repro
Steps to reproduce the behavior:
supabase/schemas
:00_function.sql
defining a UDF, and01_table.sql
defining a table with a CHECK constraint using that UDF.npx supabase db diff -f initial
.supabase/migrations
. Observe that theALTER TABLE
statement (with the CHECK constraint) appears before theCREATE FUNCTION
statement.npx supabase migration up
. See errorERROR: function only_letters(text) does not exist (SQLSTATE 42883)
.Generated migration snippet
Expected behavior
The migration file generated by
supabase db diff
should respect the dependencies defined implicitly by the file ordering insupabase/schemas
. The UDF definition should appear before the table definition that uses it in a CHECK constraint, allowingsupabase migration up
to succeed.System information
Supabase CLI version:
2.22.6
CRASH ID:
095a7affb19546f3be2f26baf9b22cd5
Additional context
db.migrations.schema_paths
inconfig.toml
does not affect this issue.--use-pg-schema
flag results in a different error (check constraints that depend on UDFs: not implemented
), aspg-schema-diff
does not support UDFs in check constraints.The text was updated successfully, but these errors were encountered: