Skip to content

fix(cli): run pg-delta/--experimental gate before mutex check in db schema declarative - #5828

Merged
Coly010 merged 4 commits into
developfrom
columferry/cli-1876-db-schema-declarative-generatesync-run-pg-delta-experimental
Jul 8, 2026
Merged

fix(cli): run pg-delta/--experimental gate before mutex check in db schema declarative#5828
Coly010 merged 4 commits into
developfrom
columferry/cli-1876-db-schema-declarative-generatesync-run-pg-delta-experimental

Conversation

@Coly010

@Coly010 Coly010 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What changed

db schema declarative generate/sync ran their mutual-exclusivity flag check (db-url/linked/local, apply/no-apply) BEFORE the pg-delta/--experimental gate (legacyRequirePgDelta). Go's cobra runs PersistentPreRunE (the gate) before ValidateFlagGroups (mutex check) — confirmed against apps/cli-go/cmd/db_schema_declarative.go and the actual cobra@v1.10.2 source — so invoking either command with conflicting flags and no --experimental surfaced the wrong error in the TS shell vs Go.

Same bug class already fixed for storage ls/cp/mv/rm in CLI-1855 (#5768); this mirrors that precedent as closely as the code structure allows. Declarative's gate needs a config read (legacyReadDbToml) that storage's didn't, so the check lives inline in each handler's body rather than at the .command.ts level — moving the config read ahead of the mutex check as part of the same reorder is also more correct (Go's PersistentPreRunE loads config unconditionally before validating flag groups too).

Swaps the order in both handlers, fixes misleading ordering comments (and two stale Go line-number citations found nearby), documents the precedence in both commands' SIDE_EFFECTS.md, and adds regression coverage for the "mutex conflict without --experimental" case in both generate and sync.

Fixes CLI-1876

…chema declarative

db schema declarative generate/sync ran their mutual-exclusivity flag
check (db-url/linked/local, apply/no-apply) before the pg-delta
--experimental gate. Go's cobra runs PersistentPreRunE (the gate)
before ValidateFlagGroups (mutex check), so a conflicting-flag
invocation without --experimental surfaced the wrong error in TS vs
Go. Same bug class already fixed for storage ls/cp/mv/rm in CLI-1855.

Swaps the order in both handlers so the gate (and the config read it
depends on) runs first, fixes misleading ordering comments, and adds
regression coverage for the "mutex conflict without --experimental"
case.

Fixes CLI-1876
@Coly010

Coly010 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: f54b2c760c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Coly010 Coly010 self-assigned this Jul 8, 2026
@Coly010
Coly010 marked this pull request as ready for review July 8, 2026 12:00
@Coly010
Coly010 requested a review from a team as a code owner July 8, 2026 12:00
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@9003d3338eeacebe5cf8ab86f2fc2afee0606ec4

Preview package for commit 9003d33.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f54b2c760c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ta gate (review: #5828)

generate/sync passed the raw --experimental flag into legacyRequirePgDelta
instead of legacyResolveExperimental, so an env-enabled experimental
session (SUPABASE_EXPERIMENTAL=true) was treated as closed. Go's gate
reads viper.GetBool("EXPERIMENTAL") (db_schema_declarative.go:78), which
falls back to the env var via viper.AutomaticEnv (root.go:318-334) — the
same fallback legacyResolveExperimental already implements and every
other pg-delta/experimental call site already uses.

Now that the gate runs before the mutex check (this PR's fix), the bug
surfaces as a wrong error for SUPABASE_EXPERIMENTAL=true ... --local
--linked (and --apply --no-apply on sync): TS reported the gate error
instead of Go's mutex error. Swap to legacyResolveExperimental in both
handlers and add regression coverage for the env-fallback case.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39bc7b49b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/legacy/commands/db/schema/declarative/generate/generate.handler.ts Outdated
@Coly010

Coly010 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

Coly010 added 2 commits July 8, 2026 13:46
…TAL (review: #5828)

legacyResolveExperimental/legacyResolveExperimentalWithProjectEnv used
`flag || env`, so SUPABASE_EXPERIMENTAL=1 could re-open the pg-delta gate
even after an explicit --experimental=false. Go's viper gives a Changed
pflag priority over AutomaticEnv regardless of its value
(viper@v1.21.0/viper.go:1176-1178) — the same precedence legacyResolveYes
already implements for --yes=false. Add the analogous explicit-false scan
for --experimental, mirroring legacyYesFlagExplicitlyFalse.
… (review: #5828)

generate/sync resolved --experimental via legacyResolveExperimental (shell
env only) before reading supabase/.env, so a SUPABASE_EXPERIMENTAL set only
in the project .env file did not open the pg-delta gate. Go's
dbDeclarativeCmd.PersistentPreRunE calls flags.LoadConfig — which runs
loadNestedEnv and os.Setenv's each project-.env key — BEFORE reading
viper.GetBool("EXPERIMENTAL") (db_schema_declarative.go:73-78,
pkg/config/config.go:789). Load the project env first and resolve against
it via legacyResolveExperimentalWithProjectEnv, matching the pattern db
reset already uses for its own yes/experimental gates.
@Coly010
Coly010 added this pull request to the merge queue Jul 8, 2026
Merged via the queue into develop with commit 85bf2ce Jul 8, 2026
34 checks passed
@Coly010
Coly010 deleted the columferry/cli-1876-db-schema-declarative-generatesync-run-pg-delta-experimental branch July 8, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants