fix(cli): preserve view reloptions in db diff output#5478
fix(cli): preserve view reloptions in db diff output#5478nirav-gondaliya wants to merge 1 commit into
Conversation
Re-attach pg_class.reloptions to CREATE VIEW statements emitted by db diff, so declarative schemas containing `with (security_invoker=true)` (or any other view-level reloption) round-trip through the generated migration instead of silently losing the clause. The patcher hooks into DiffDatabase, so the fix applies to every diff engine (migra, migra-bash fallback, pg-schema-diff, pg-delta). On engines that already emit the WITH clause (e.g. pg-schema-diff), the regex deliberately does not match, leaving their output untouched. Closes supabase#3973
|
Hey there ! Thank's for your contribution. Moving forward we want to deprecate diff based on Could you give it a try ? This code path will be removed bit by bit as users migrate and |
|
Hey @avallete , thanks for the pointer, confirmed
One open question before I close: pg-delta is still flagged experimental and
Either works for me — your call on which fits the deprecation timeline better. |
|
Hey there ! Thanks for testing it out ! We plan to make delta the new default very soon, this issue/limitation with migra has been around for a long time. I think we can rely on pg-delta being pushed along as the new default. |
|
Sounds good — closing this in favor of pg-delta then. Thanks @avallete for the quick turnaround let me know if I can help with specific issues. Closes without merge — fix is already covered by |
Summary
supabase db diffwas silently dropping theWITH (...)clause onCREATE VIEWstatements (security_invoker,security_barrier,check_option, plus reloptions on materialized views). The underlying diff engines (djrobstep/migra, @pgkit/migra) don't readpg_class.reloptions, so a declarative view defined asended up in the generated migration as create or replace view "public"."user_details" as SELECT ...
— silently turning a SECURITY INVOKER view into a SECURITY DEFINER one and bypassing RLS on the underlying table.
What changed
Scope
This PR closes the new-view case from #3973. A related gap surfaced during testing — migra doesn't detect reloption-only changes on existing views, so flipping security_invoker=true → false on an already-applied view produces No schema changes found. That is a separate migra limitation (the patcher only runs when there's a CREATE VIEW to patch) and is tracked separately at #5476.
Why the fix is engine-agnostic
The patcher's regex matches view "x"."y"\s+as — bare as. Engines that already emit with (...) between the name and as (e.g. pg-schema-diff) do not match the regex and pass through unchanged.
Closes #3973