Repository navigation
Closed
Labels
Description
Describe the bug
I'm using the pre-release version with the pgmq changes. The declarative generate now works correctly. The sync command also no longer crashes.
But when using sync without changing anything, always seems to try and generate a migration for a trigger that simply does not change at all.
To Reproduce
Steps to reproduce the behavior:
- Run
supabase db schema declarative generate --local - Run
supabase db schema declarative sync - Observe that it tries to generate a migration for a trigger that already exists in the DB 1to1
Expected behavior
Given a migration file with:
# migrations/01_initial.sql
create trigger "trg_update_priority_scores"
before insert or update of visitors_total_count, start_date, background_images, priority_override_score
on "my_schema"."tournaments"
for each row
execute function "my_schema"."update_priority_scores"();And a schema file:
# database/schema/my_schema/tables/tournaments.sql
CREATE TRIGGER trg_update_priority_scores
BEFORE INSERT OR UPDATE OF visitors_total_count, start_date, background_images, priority_override_score ON my_schema.tournaments
FOR EACH ROW
EXECUTE FUNCTION my_schema.update_priority_scores();I would have expected nothing to be generated.
But instead
The declarative commands generates only this migration:
# migrations/20260416140754_declarative_sync.sql
CREATE OR REPLACE TRIGGER trg_update_priority_scores BEFORE INSERT OR UPDATE OF visitors_total_count, start_date, background_images, priority_override_score ON my_schema.tournaments FOR EACH ROW EXECUTE FUNCTION my_schema.update_priority_scores();When I
- apply this generated migration to my db
- rerun the
synccommand again - it, again, generates a migration with the same exact trigger
Screenshots
If applicable, add screenshots to help explain your problem.
System information
Rerun the failing command with --create-ticket flag.
- Version of OS: MacOS 26.4.1
- Version of CLI: v2.91.2
- Version of Docker: v4.69.0
- Versions of services: [output from
supabase servicescommand]
SERVICE IMAGE | LOCAL | LINKED
------------------------|------------------------|--------
supabase/postgres | 15.8.1.085 | -
supabase/gotrue | v2.188.1 | -
postgrest/postgrest | v14.8 | -
supabase/realtime | v2.82.0 | -
supabase/storage-api | v1.48.28 | -
supabase/edge-runtime | v1.73.3 | -
supabase/studio | 2026.04.08-sha-205cbe7 | -
supabase/postgres-meta | v0.96.4 | -
supabase/logflare | 1.37.1 | -
supabase/supavisor | 2.7.4 | -
Activity
avallete commentedon Apr 16, 2026
Hey ! Thank's for reporting ! I will have a look.
That might be due to a missing normalization in the definition of the trigger 🤔
I'm curious, what happen if you replace your
migrations/01_initial.sqldefinition with the one produced by the output (CREATE OR REPLACE TRIGGER trg_update_priority_scores BEFORE INSERT OR UPDATE OF visitors_total_count, start_date, background_images, priority_override_score ON my_schema.tournaments FOR EACH ROW EXECUTE FUNCTION my_schema.update_priority_scores();)Does it still generate diff's ?
tolgap commentedon Apr 16, 2026
Hey @avallete
If I replace the trigger in
01_initial.sql, and then rundeclarative generateand thendeclarative sync, it still generates the same exact trigger in the diff in a<timestamp>_declarative_sync.sql.avallete commentedon Apr 17, 2026
Hey there !
I've tried to reproduce with this MRE:
But, doing so, I can't get the same issue. So I'm suspecting that something else causes this change to always appears.
What happen if you do
npx supabase@latest db schema declarative sync --no-cache? I'm thinking the issue could be due to some catalog caching persisting instead of being replaced.tolgap commentedon Apr 17, 2026
@avallete
I downloaded the latest supabase CLI (v2.92.1)
Here's the lines:
So the
--no-cachedidn't help out.avallete commentedon Apr 17, 2026
Hey @tolgap!
Thanks for the answer. Sadly, I still can’t reproduce the issue with the MRE you shared. Would you be able to put together one that reproduces the bug and share it somewhere I can access?
Otherwise, would you mind sharing your full
supabase/migrationsandsupabase/databasefolders so I can try to reproduce it on my end? If you’d prefer not to share it publicly, you can add me to a private repo and I’ll take a look.tolgap commentedon Apr 20, 2026
@avallete I cannot add you to our codebase. And I do not want to make any of our migrations/schema public. If possible, I could zip our
supabase/folder and email it to you? If you could (cryptically) provide me your email address.Otherwise you can email me directly: <firstname> at <companyname without app suffix>.nl
PS: I've spent quite some time to create an MRE, but there are a LOT of migrations and tables. At some point, removing the clutter around it, the problem just stops happening but its definitely unrelated clutter. It would still be a gigantic MRE.
avallete commentedon Apr 20, 2026
No worries about the MRE what you’re describing (the issue disappearing when removing seemingly unrelated parts) usually points to some subtle interaction, so having the full setup will actually help more.
Thanks for taking the time to dig into it, I've emailed you on your GitHub contact email 👍
avallete commentedon Apr 21, 2026
Hey there !
Quick update, I've been able to reproduce and identify the root cause of the issue on my end. Working on a fix right now.
tolgap commentedon Apr 21, 2026
That is great to hear @avallete . Thank you so much!
chore(deps): upgrade pg-delta to alpha.17 (#5110)
tolgap commentedon Apr 24, 2026
@avallete I have tried CLI version v2.93.1 and v2.95.0 but these are failing to generate any diff at all. I just get a generic error:
It does generate the files, but running
syncerrors in the same way without generating any diff. Even if I change a function body in the migrations I had sent you:(changed some random function body in
schema/database/**/functions/my_function.sql:There's no additional info in the debug/error.txt
You could try it out with the same exact migrations I had sent you. I'm not sure if it is a new issue or related to this.
avallete commentedon Apr 24, 2026
Hey @tolgap, thank's for closing the loop. I can't reproduce on my end with your use case. However, your schema only generate 1625 statements on my end while it does 1633 on yours.
I wonder if the issue might be due to invalid sql in your declarative schema. It seems like the validation errors for function were swallowed from the output (got a PR here to fix it: #5120)
That would explain why the statement get applied (a function body containing an invalid SQL will still be applied with
set check_function_body=falseit will only fail at runtime. And at the end of the apply we run one pass to check all the functions bodies (which would explain why it fail at this point).If you updated the function boddy with an additional valid statement (such as
SELECT 1;) do you still face the issue ?Would you be willing to send me the actual function body you are changing so I can try and reproduce on my end ?
Prod deploy (#5109)
chore: resync develop with main (#5123)
tolgap commentedon Apr 28, 2026
Hey @avallete
With your recent fix from #5120, I just updated my CLI to v2.95.4 and I see the issue. We've had recently done a
ALTER TABLE ... RENAME TO ...but one of the function bodies still referenced the old table name.So yeah it was definitely an error on our end, but now we can actually see what the error is 🙂.
chore(deps): upgrade pg-delta to alpha.17 (#5110)
chore: resync develop with main (#5123)
fix: encode auth external url explicitly (#5092)
chore: resync develop with main (#5123)