Skip to content

Commit c27a649

Browse files
authored
fix(db): preserve immutable artifact persistence (#145)
## Summary - Fix generated media persistence by removing an unnecessary row lock on immutable output metadata. - Keep serialization at the existing per-user advisory transaction boundary. - Consolidate the pre-launch database history into one current-schema baseline and one snapshot. - Enforce that the agent role can insert/read generated outputs but cannot update them. ## Decisions Made | Decision | Choice | Reasoning | |---|---|---| | Concurrency boundary | Existing per-user advisory transaction lock | It already serializes reservation and finalization; a second row lock on immutable output rows was redundant. | | Runtime permissions | Keep bounded INSERT/SELECT and no UPDATE | Generated output metadata is immutable after publication. | | Migration history | One clean baseline | This is a pre-launch implementation and does not retain compatibility migrations. | ## How to Review 1. Review `packages/db/src/artifact-upload-intents.ts` for the transaction change. 2. Review `scripts/supabase-target/index.ts` for the immutable ACL assertion. 3. Verify `packages/db/drizzle` contains one SQL baseline, one snapshot, and one journal entry. ## Test Plan - [x] `pnpm --filter @cheatcode/db db:generate` (no schema changes) - [x] `pnpm turbo typecheck` - [x] `pnpm turbo lint` - [x] `pnpm turbo build` - [ ] Rebaseline the verified production Drizzle ledger and run migration dry-run - [ ] Deploy the agent Worker - [ ] Generate images in production with natural-language and explicit-action prompts ## Linear No Linear issue was provided for this production fix. ## Plan No repository plan document was required for this bounded fix.
1 parent 7521d49 commit c27a649

11 files changed

Lines changed: 111 additions & 6304 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)