Skip to content

Commit b335cbe

Browse files
committed
fix(db): preserve immutable artifact persistence
Use the existing tenant advisory lock instead of requesting UPDATE access on generated outputs. Consolidate the pre-launch schema into one baseline and enforce immutable output grants in production validation.
1 parent 7521d49 commit b335cbe

11 files changed

Lines changed: 92 additions & 6285 deletions

packages/db/README.md

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ mime, filename, and R2 object identity.
5353
- Assistant transcript segments are unique by run and segment, with one final
5454
segment marker.
5555
- Provider-key rows contain Vault references and non-secret fingerprints only.
56-
- Generated outputs and upload intents bind user, run, and project ownership.
56+
- Generated outputs are immutable after publication. Upload intents bind user,
57+
run, and project ownership while the per-user project-mutation advisory lock
58+
serializes reservation and finalization.
5759
- Agent-run skill-runtime capabilities store only bounded, short-lived digests;
5860
the agent role rotates them under signed user context and terminal transitions
5961
clear them.
@@ -106,25 +108,9 @@ External provider calls occur outside database transactions and advisory locks.
106108

107109
## Migrations
108110

109-
The repository keeps a single current-schema Drizzle baseline at
110-
`drizzle/0000_current_schema.sql`, its generated snapshot, and the journal.
111-
Future schema changes append ordinary forward Drizzle migrations. The
112-
pre-launch historical migration archive is intentionally absent.
113-
114-
The baseline's checksum was intentionally revised on 2026-07-31 to remove
115-
unrunnable `supabase_admin` default-ACL recreations (platform-managed state the
116-
`postgres` migration role is denied on every Supabase project). Databases that
117-
recorded the pre-revision baseline fail ledger verification with "Migration
118-
ledger diverges from source at position 0." The one-time remedy, run once as
119-
the migration admin against that database only:
120-
121-
```sql
122-
update drizzle.__drizzle_migrations
123-
set hash = '<sha256 of the current drizzle/0000_current_schema.sql>'
124-
where created_at = 1784981026716;
125-
```
126-
127-
Compute the hash with `shasum -a 256 packages/db/drizzle/0000_current_schema.sql`.
111+
The repository keeps one current-schema Drizzle baseline at
112+
`drizzle/0000_current_schema.sql`, one generated snapshot, and one journal
113+
entry. The pre-launch migration history is intentionally absent.
128114

129115
```bash
130116
pnpm --filter @cheatcode/db db:generate
@@ -142,11 +128,10 @@ The migration runner:
142128
6. validates the complete current table, column, constraint, index, function,
143129
RLS, grant, role, and data-integrity contract.
144130

145-
The target-parity migration also installs the required Supabase extensions and
146-
removes the `anon`, `authenticated`, and `service_role` access and default ACLs
147-
from `public`. This schema-USAGE revoke is deliberate because Cheatcode does
148-
not use the Supabase Data API. Supabase-managed Vault-schema grants remain
149-
untouched.
131+
The baseline installs the required Supabase extensions and removes the `anon`,
132+
`authenticated`, and `service_role` access and default ACLs from `public`. This
133+
schema-USAGE revoke is deliberate because Cheatcode does not use the Supabase
134+
Data API. Supabase-managed Vault-schema grants remain untouched.
150135

151136
`pnpm dev:setup` supplies the role passwords and signed-context Vault rows that a
152137
schema migration cannot safely embed, then proves real logins and signed tenant

0 commit comments

Comments
 (0)