Declarative schema migration generation broken for JOIN views after CLI update

Open
#4,027 17 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
postgresql, typescript
Domain
cli, databases

Research direction

Start by reproducing the behavior with Supabase CLI 2.34.3 using a declarative schema in supabase/schemas/*.sql and a view containing a JOIN. Trace the supabase db diff path and its SQL deparser, comparing the generated DROP VIEW / CREATE VIEW statements across repeated runs. Done means an unchanged JOIN view produces no migration output after the migration is applied.

Written by the indexing model from the issue text.

Description

🐛 Bug do-not-close supabase/cli

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:

  1. Upgrade to the latest Supabase CLI
  2. Have a project using declarative schema (supabase/schemas/*.sql).
  3. 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;
  1. Create migration with supabase stop && supabase db diff -f migration_name
  2. 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.

Dominant language
TypeScript
Stars
2.4k
Forks
523
Avg merge
20h 47m
Merged PRs (30d)
243

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/cli

All issues in supabase/cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.