fix(db): GRO-2722 schema-safe reset (TRUNCATE, no DROP) [uat→main] #243
Reference in New Issue
Block a user
Delete Branch "uat"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
GRO-2722 — Schema-safe reset (TRUNCATE, no DROP)
Phase 4 — uat→main | UAT ✅ | Security ✅
Summary
Replaced destructive DROP-based reset (
DROP TABLE,DROP TYPE,DROP SCHEMA) inpackages/db/src/reset.tsandapps/api/src/db/reset.tswith a schema-safeTRUNCATE <all public tables> RESTART IDENTITY CASCADE.Table names are enumerated dynamically from
pg_tables WHERE schemaname='public'— thedrizzleschema and__drizzle_migrationstable are excluded, keeping drizzle-kit migrate a no-op on already-migrated DBs.This is the root-cause fix for the GRO-2678 prod outage.
Key changes
packages/db/src/reset.ts— TRUNCATE path with advisory lock, migration, seed, prod guardapps/api/src/db/reset.ts— mirrored copy (in-sync with packages/db)UAT_PLAYBOOK.md §3 TC-API-3.30— manual CronJob trigger + schema-safe verificationPreserved controls
NODE_ENV=production && ALLOW_RESET!='true' → exit(1))withSeedAdvisoryLockwraps TRUNCATE → migrate → seedmax: 6(deadlock prevention)if (tables.length > 0))Review trail
UAT Playbook
Updated
UAT_PLAYBOOK.md §3 — TC-API-3.30(new test case for schema-safe CronJob reset).✅ CTO Code Review — APPROVED (Phase 4, uat→main)
Head:
8b812df— GRO-2722 schema-safe resetCorrectness
DROP TABLE/DROP TYPE/DROP SCHEMA drizzle) fully replaced by a singleTRUNCATE <all public tables> RESTART IDENTITY CASCADE.CASCADEhandles FK cycles;RESTART IDENTITYresets sequences soseed.ts's deterministic PK derivation stays correct.pg_tables WHERE schemaname='public';drizzle/__drizzle_migrationsare in a separate schema and therefore preserved →drizzle-kit migratestays a no-op on an already-migrated DB. This is the correct root-cause fix for the GRO-2678 prod outage."${name.replace(/"/g,'""')}") — correct SQL identifier quoting.Preserved controls (verified against full file, not just the diff)
NODE_ENV==='production' && ALLOW_RESET!=='true' → exit(1).withSeedAdvisoryLockstill wraps the whole TRUNCATE → migrate → seed chain (GRO-2139/2123).max: 6(reserve + work headroom) unchanged.if (tables.length > 0).packages/db/src/reset.ts(deployed entrypoint) andapps/api/src/db/reset.tskept in sync; the new doc comment correctly points destructive local teardown atdb:nuke.Review trail
CI note
CI / Test (pull_request)initially failed on an unrelated, flaky test —apps/api/src/__tests__/authProvider.test.ts:245("returns 400 for missing clientSecret"), a network-dependent OOBE test-connection that (unlike its sibling at :231) omits the}, 15000)timeout override while the route has a 10s fetch timeout, so it can trip the default 5s vitest timeout depending on DNS/network toauth.example.com. It is not in the files under review. Re-run went green (Test ✓ in 51s). Filing a separate follow-up to de-flake that test. The residual aggregate red is the staleCI / Test (push)status from the original Aug-16 push event, not PR validation.Approving on the merits. Merge into protected
mainto be executed by the CEO (gb_flea lacks merge rights onmain).