Repository navigation
Conversation
`db reset --remote` dropped every user object in one transaction, so every dropped relation, index, sequence, type and function kept its lock until COMMIT. On databases with a few thousand objects that went past max_locks_per_transaction and failed with `out of shared memory` (SQLSTATE 53200) before any migration ran. The drop still runs in one transaction first, so a failure changes nothing. Only when that transaction runs out of lock slots (SQLSTATE 53200 with "out of shared memory") is it rolled back and retried with a commit after every step. The per-object path truncates the migration history first, so a partial reset never reports migrations as applied, and every failure in it says the database is partly reset and how to finish. When a single object still exhausts the lock table, the hint names the project ref, derived from a Supabase db-url when needed, and offers `postgres-config update` or `[db.settings]` with `config push`. Local databases and non-Supabase URLs get a matching hint without a ref. `db reset` and `migration down` now share one drop helper, so both get the same fallback and hints. Fixes #7898
CLI benchmark (Lightweight Commands): no changes foundCommit
API calls: unchanged for all 9 commands. Binary size: 135.7 MB, up 4.0 KB from 135.7 MB. Details: timing ranges, API calls per command, slowest phasesTiming ranges
API calls per command
Slowest phasesNo command moved beyond noise, so there are no phase deltas. Comment |
There was a problem hiding this comment.
Superseded by a newer AI review
🤖 AI Review
CLI reference prose guidance: snapshot supabase/supabase@b6c391a supplied to reviewers (advisory, not a style pass).
Confirmed all eight Codex findings. Claude reported none. Two findings are major: localized or ambiguous Postgres errors can lead the CLI to choose the wrong reset strategy, and truncating migration history before dropping user schemas can make previously successful atomic resets fail. The fallback can also start without a confirmed rollback and report partial changes before anything commits. I checked the added reference prose against the supplied style snapshot. Verification was static.
Findings
| Severity | Location | Category | Sources | Claim |
|---|---|---|---|---|
| 🟠 MAJOR | apps/cli/src/command-internal/drop-objects.ts:192 |
error-handling |
codex | The CLI uses an English error message to decide whether to switch to a reset that commits partial progress. |
| 🟠 MAJOR | apps/cli/src/command-internal/drop-objects.ts:40 |
database-correctness |
codex | Truncating migration history before dropping user schemas can make previously successful atomic resets fail. |
| 🟡 MINOR | apps/cli/src/command-internal/drop-objects.ts:254 |
transaction-handling |
codex | The fallback can run on the same session without confirming that the atomic transaction ended. |
| 🟡 MINOR | apps/cli/src/command-internal/drop-objects.ts:264 |
error-handling |
codex | The fallback reports that the database changed and migration history was cleared even when its first SQL operation fails. |
| 🟡 MINOR | apps/cli/src/command-internal/drop-objects.ts:207 |
recovery-guidance |
codex | The local and hosted recovery instructions can leave the lock setting unchanged or lower it on an already tuned database. |
| 🟡 MINOR | apps/cli/docs/supabase/db/reset.md:15 |
docs-drift |
codex | The overlay says the fallback drops database objects one at a time, but a single fallback transaction can drop a schema and its dependent objects together. |
| 🟡 MINOR | apps/cli/src/command-internal/drop-objects.unit.test.ts:209 |
test-coverage |
codex | The new SQL test can pass even if the fallback never clears migration history or commits any drops. |
| ⚪ NIT | apps/cli/src/command-internal/drop-objects.ts:258 |
tracing |
codex | The successful drop span does not identify which reset strategy completed. |
Stats
Claude findings: 0 · Codex findings: 8 · Confirmed: 8 · Refuted: 0 · Uncertain: 0
Models: claude-opus-5-5 + gpt-6.2-sol · Trigger: auto · Workflow run
This review runs once per PR. A maintainer can request another with a /ai-review comment.
- Detect lock exhaustion from the Postgres hint naming max_locks_per_transaction, which stays untranslated in every locale, instead of the English message. DbExecError now carries the hint. - Keep the original truncation order in the single-transaction drop; only the per-object drop clears migration history first. - Fall back only after the drop statement itself fails and the rollback succeeds; a failed rollback reports both errors. - Say the database may be partly reset, since the first per-object step can fail before anything commits. - Ask users to check the current max_locks_per_transaction and raise it, with 1024 as an example. - Annotate the drop span with the strategy used.
|
/ai-review |
There was a problem hiding this comment.
🤖 AI Review
CLI reference prose guidance: snapshot supabase/supabase@b53403e supplied to reviewers (advisory, not a style pass).
Confirmed all five Codex findings. The fallback can exhaust the lock table before dropping any schemas, and interrupting migration down --last can leave the user without the version-pinned recovery command. The reset reference overstates when a retry occurs, and the new tests leave PostgreSQL transaction behavior unverified. The prose finding is advisory. Claude reported zero findings. The supplied next context shows no fundamental conflict. Verification used source inspection.
Findings
| Severity | Location | Category | Sources | Claim |
|---|---|---|---|---|
| 🟠 MAJOR | apps/cli/src/command-internal/drop-objects.ts:37 |
correctness |
codex | The per-object fallback can exhaust the lock table before reaching the schema drops. |
| 🟡 MINOR | apps/cli/src/command-internal/drop-objects.ts:284 |
error-handling |
codex | Interrupting migration down --last during the fallback can clear the history used to select the rollback version before the CLI prints the recovery command. |
| 🟡 MINOR | apps/cli/docs/supabase/db/reset.md:15 |
docs-drift |
codex | The remote reset reference promises a retry for transaction lock exhaustion. A lock-exhaustion error during COMMIT returns immediately. |
| 🟡 MINOR | apps/cli/src/command-internal/drop-objects.unit.test.ts:246 |
test-coverage |
codex | The new tests leave the fallback's per-operation commits unverified in PostgreSQL. |
| ⚪ NIT | apps/cli/docs/supabase/db/reset.md:15 |
docs-style |
codex | The fallback sentence combines the retry condition, commit behavior, and scope of schema deletion. |
Stats
Claude findings: 0 · Codex findings: 5 · Confirmed: 5 · Refuted: 0 · Uncertain: 0
Models: claude-opus-5-5 + gpt-6.2-sol · Trigger: manual · Workflow run
This review runs once per PR. A maintainer can request another with a /ai-review comment.
| const migrationsFirst = commitEach | ||
| ? ` | ||
| for rec in | ||
| select * | ||
| from pg_class c | ||
| where c.relnamespace::regnamespace::name = 'supabase_migrations' and c.relkind = 'r' | ||
| loop | ||
| raise notice 'truncating table: %.%', rec.relnamespace::regnamespace::name, rec.relname; | ||
| execute format('truncate %I.%I cascade', rec.relnamespace::regnamespace::name, rec.relname);${commit} | ||
| end loop; |
There was a problem hiding this comment.
🟠 MAJOR · correctness · source: codex
The per-object fallback can exhaust the lock table before reaching the schema drops.
Evidence: apps/cli/src/command-internal/drop-objects.ts:37–55 runs TRUNCATE ... CASCADE on each supabase_migrations table before entering the schema loop. PostgreSQL locks foreign-key referencing tables in the same truncate transaction. References across several schemas can exhaust the lock table before the separate schema drops at line 68 run.
Suggested fix: Defer cascading truncation until after the user schema and table drops. Track an incomplete reset separately if migration history must be invalidated before the first drop.
| describe("drop SQL", () => { | ||
| it("commits after every step only in the per-object block", () => { | ||
| expect(count(dropObjectsSql, "commit;")).toBe(0); | ||
| expect(count(dropObjectsEachSql, "commit;")).toBe(count(dropObjectsEachSql, "execute format(")); | ||
| }); | ||
|
|
||
| it("clears the migration history first only in the per-object block", () => { | ||
| const history = "'supabase_migrations'"; | ||
| expect(dropObjectsEachSql.indexOf(history)).toBeLessThan( | ||
| dropObjectsEachSql.indexOf("drop schema if exists"), | ||
| ); | ||
| expect(dropObjectsSql.indexOf(history)).toBeGreaterThan( | ||
| dropObjectsSql.indexOf("drop table if exists"), | ||
| ); |
There was a problem hiding this comment.
🟡 MINOR · test-coverage · source: codex
The new tests leave the fallback's per-operation commits unverified in PostgreSQL.
Evidence: apps/cli/src/command-internal/drop-objects.unit.test.ts:247–259 counts SQL tokens and checks substring positions. The fake session at lines 40–49 and the reset integration stub at apps/cli/src/commands/db/reset/reset.integration.test.ts:261–282 return outcomes from SQL-string matches. The fallback test at lines 3085–3104 checks the statements sent and migration progress output.
Suggested fix: Add a PostgreSQL-backed test that forces a later fallback operation to fail and verifies that an earlier drop and the migration-history truncation remain committed.
- Treat a lock-exhaustion failure on COMMIT like one from the drop statement: roll back and retry in separate transactions. - Print how to finish in the fallback warning, before anything can commit, so an interrupted migration down still shows the pinned db reset --version command. - Split the reset.md fallback sentence.
Summary
supabase db reset --remotedrops every user object in one transaction, so every dropped table, index, sequence, type and function holds its lock until the commit. On a database with a few thousand objects that runs pastmax_locks_per_transactionand fails without of shared memory(SQLSTATE 53200) before any migration runs. Changing that setting needs a restart, so there was no way around it from the CLI.What changes:
max_locks_per_transaction, since 53200 on its own also covers plain out of memory and the message text is translated with the server locale (setting names aren't).DbExecErrornow carries the hint. It prints a line on stderr when it falls back.supabase_migrationsfirst, so a partial reset never shows migrations as applied. The single-transaction path keeps the original order.max_locks_per_transactionand raising it. For a linked project, or a Supabase connection string the ref can be read from, it points atsupabase postgres-config update --experimentalor[db.settings]plussupabase config push. A local database gets the[db.settings]and restart route, and any other Postgres is pointed atpostgresql.conf.migration downuses the same drop SQL, so it now goes through the same helper and gets the same fallback and hints. Its partial-state hint points atsupabase db reset --version <version>rather than re-runningmigration down, because--lastcan't work once the history has been cleared.Testing
db resetandmigration down.postgres:17withmax_locks_per_transaction=10andmax_connections=20, running the CLI from source:postgresql.confhintreset.live.test.ts.Follow-ups (not in this PR)
publicloops don't skip objects that belong to an extension (there's nopg_dependdeptype = 'e'anti-join like the schema loop has), so something likeuuid-osspinstalled inpublicfails with 2BP01 onuuid_nil(). That still fails with this PR, but now nothing gets dropped.relkind = 's', but sequences are'S', so standalone sequences inpublicare never dropped.raise noticeoutput, or at least the object that failed, when the drop errors.Linked issue
Fixes #7898
open-for-contributionlabel (or I'm a Supabase maintainer).Checklist
fix(cli): …).pnpm check:allpasses; relevant package tests pass for every touched workspace, andpnpm types:checkpasses for each touched TypeScript workspace (or workspace declaring it).