Description
Describe the bug
After upgrading to the latest Supabase CLI (2.34.3), supabase db diff in declarative schema mode is endlessly re-generating migrations for views that contain JOINs, even if no actual changes have been made to the view SQL.
Before the CLI update, these views were stable. Now, after every db diff, the same DROP VIEW / CREATE VIEW statements are produced, leading to an infinite migration loop.
To Reproduce
Steps to reproduce the behavior:
- Upgrade to the latest Supabase CLI
- Have a project using declarative schema (supabase/schemas/*.sql).
- Include a view with a join, for example:
create or replace view public.timeslips_view as
select
o.name,
tr.timeslips_requested,
tr.created_at,
tr.download_link,
tr.modified_at
from public.timeslips_requests tr
left join public.organisations o on tr.organisation_id = o.id
order by tr.created_at desc;
- Create migration with
supabase stop && supabase db diff -f migration_name - Re-run the diff
Expected behavior
If no changes have been made to the database or declarative schema, supabase db diff should produce no output.
Actual behavior
The CLI repeatedly outputs the same DROP VIEW / CREATE VIEW statements for affected views. This repeats indefinitely after each run, even immediately after applying the migration.
Notes / Observations
• The issue appears specific to views containing JOINs — views without joins are unaffected.
• Happens whether or not schema qualification (public.) is used in the FROM clause.
• Removing WITH (security_invoker...) and ALTER ... OWNER from the declarative schema does not resolve it.
• Likely linked to a change in the CLI’s SQL deparser in the most recent release.
Activity
nicksiscoe commentedon Aug 20, 2025
Noticing exact same behavior when upgrading to
2.34.3. If I revert to2.34.0this bug doesn't happen.lavisht22 commentedon Oct 6, 2025
Did you find any solutions to this? I don't have declarative schemas and this is still happening with me.
nicksiscoe commentedon Oct 8, 2025
@lavisht22 Updating to latest supabase cli seems to work for me. Currently on
2.40.7YA9 commentedon Nov 6, 2025
Getting the same issue
speedpro commentedon Nov 7, 2025
I'm getting the same issue, but mine doesn't have a join:
It's odd. I had only one view which was stuck in this loop, but since switching to declarative schemas, I now have three views which are stuck in this loop.
nicksiscoe commentedon Nov 7, 2025
This was briefly fixed for a few versions and has come back on the latest few versions... No issues on
2.40.7-ish but on latest it's broken againjperasmus commentedon Nov 19, 2025
Is there a known workaround for this for now? I think the limitation I am running into is because my views have
security_invokerset, which I see is part of the known limitations. It recreates the views every time I run the diff.jdharrisnz commentedon Nov 19, 2025
@jperasmus Switching the diff tool with
--use-pg-schemaworked for me. The defaultmigrahasn't been updated in years, and I read that Supabase will be changing the default to pg schema in the future. As always, closely check your migration files!jperasmus commentedon Nov 20, 2025
Thanks @jdharrisnz I tried
pg-schema-diffnow, which looked promising. Unfortunately, it looks like it doesn't currently support indexes on materialized views, so it is erroring out for me. stripe/pg-schema-diff#173chaintng commentedon Nov 28, 2025
having same issue also
paulteriele commentedon Jan 19, 2026
I'm experiencing the same issue while diffing our declarative schema against our migrations. Versions of Supabase CLI higher than v2.53.6 (the latest I've tested with is v2.72.7) will repeatedly (endlessly) result in migration file (with the exact same contents) for all views and materialized views that joins one or more times.
This prevents us from upgrading our CLI forwards from v2.53.6.
To Reproduce
$ supabase db diff -f changes(multiple times)System information
Result
This will repeatedly (endlessly) result in migration file (with the exact same contents) for all views and materialized views that joins one or more times.
Expected Behavior
$ supabase db diff -f changesonce)Failed workarounds
$ supabase db diff --use-pg-schema -f changes$ supabase db diff --use-pg-delta -f changessupabase db diff --use-pgadmin -f changesSuccesfull workaround
Downgrading Supabase CLI to v2.53.6
DropbackHQ commentedon Feb 5, 2026
This is still not resolved on latest 2.75.0 so we can't upgrade :(
ChinaeduO commentedon Mar 30, 2026
Any updates on this, it is open for a long time and blocking us from updating.
christopheroka commentedon Apr 12, 2026
Downgrading to
2.50.0worked for menicbyron commentedon May 8, 2026
@sweatybridge any updates on this? Haven't been able to update the CLI for a long time now...
avallete commentedon May 8, 2026
Hi there ! We've been working over
pg-deltathose past few months. We are looking for feedbacks:https://github.com/orgs/supabase/discussions/44938
arnaud-aivision commentedon Aug 1, 2026
Still reproducing on CLI 2.109.1 (Postgres 17.6), so this isn't limited to the 2.34.x era.
Two data points that may narrow it, plus a consequence I don't think has been raised in this thread.
It isn't only JOIN views
Our affected view has no JOIN — the subscription lookup is a correlated scalar subquery:
An earlier revision of the same view used
left join lateral (...) on trueand also never converged, so both forms are affected.I confirmed programmatically that live
pg_get_viewdef(..., false)and the definition the diff proposes are identical once whitespace and schema qualification are normalised — the diff is proposing to replace a definition with itself.I also tried to minimise it and failed: five synthetic views (correlated subquery; plain control; plain +
security_invoker; a full structural clone withsecurity_invoker+ subquery +where+ outerlimit 1; and one with a user-defined enum output column) were each materialised viadb diff -f+db reset, and all five converged. Only the real view keeps regenerating. That's consistent with the deparser theory in the original report rather than anything about the view's shape.The consequence:
drop viewalso discards the view's privilegesThe generated statement is
drop view if exists ...followed bycreate or replace view .... Neither reloptions nor privileges are re-emitted, andDROP VIEWdiscards both. So committing the generated output:security_invoker = true— the view then runs with the owner's privileges and RLS on the underlying tables no longer applies to it (in our schema that also bypasses aRESTRICTIVEpolicy gating a column behind MFA); andWe hit both by committing the generated statement, and caught (2) only because a pgTAP test failed. We now hand-append compensations to any migration that includes this recreate:
The reloptions half is tracked in #3973 / #5476 / #792 / #3487, but I couldn't find the privileges half reported anywhere.
Because the diff never converges, this statement reappears in every subsequent
db diff -f— so it's a permanent trap rather than a one-off, and it's silent unless something happens to exercise the view under a non-owner role.Suggestion
Even if the non-convergence is hard to pin down, having
db diffpreserve reloptions and privileges when it emits a view recreate would remove the sharp edge — the perpetual statement would at least be harmless.Happy to run experiments against a specific hypothesis if that would help.