[#2] Supabase schema migration and client helper#45
Conversation
P0-2a: SQL migration with storylines, plots, donations tables per §4.1. Includes UNIQUE(tx_hash, log_index), foreign keys, writer_type, hidden columns. P0-2b: lib/supabase.ts with browser (anon) and server (service role) clients. Fixes #2 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
T2b review: APPROVE
Schema review against issue #2 requirements:
✅ Three tables (storylines, plots, donations) — all present
✅ UNIQUE(tx_hash, log_index) deduplication constraints on all three tables
✅ Foreign keys: plots.storyline_id → storylines(id), donations.storyline_id → storylines(id)
✅ writer_type smallint not null default 0 on storylines — indexer-set, well-commented
✅ hidden boolean not null default false on storylines and plots (not on donations) — matches §8
✅ Useful indexes on writer_address and storyline_id FKs
✅ amount text for wei — avoids precision loss, correct choice
lib/supabase.ts:
✅ Browser client (anon key, respects RLS) with null fallback when env vars missing
✅ Server client (service role, bypasses RLS) with auth disabled — correct pattern
✅ Full Database interface with Row/Insert/Update types matching SQL exactly
✅ Convenience type aliases exported
Minor note (non-blocking): plots.storyline_id references the surrogate PK storylines.id, not the on-chain storylines.storyline_id. The naming overlap could confuse future contributors — consider renaming the FK column to storyline_fk or adding a code comment in a future PR. Not blocking since the relational logic is correct.
Clean, spec-compliant implementation.
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: REQUEST CHANGES
Summary
The PR is close, but the schema currently bakes in one silent data-classification bug and one relationship mismatch that will make the indexer harder to implement correctly.
Findings
-
[high]
writer_typeis supposed to be indexer-set, but the migration gives itdefault 0- File:
supabase/migrations/00001_schema.sql:16 - Suggestion: remove the default and require inserts to provide
writer_typeexplicitly, so rows cannot silently land ashumanwhen the indexer forgets or fails to set it.
- File:
-
[high] Child
storyline_idforeign keys point at the surrogate row id instead of the storyline identifier- File:
supabase/migrations/00001_schema.sql:31 - Suggestion: align the relationship so
plots.storyline_idanddonations.storyline_idreference the canonical storyline identifier defined in the schema/proposal, rather thanstorylines.id. As written, a chain event carryingstoryline_idcannot be inserted directly without an extra lookup/translation step, and the column name becomes misleading.
- File:
Decision
Request changes. The current migration risks silently misclassifying writer type and creates a storyline relationship that does not match the event-facing identifier implied by the schema.
…ne_id 1. writer_type: nullable (NULL=unclassified, 0=human, 1=agent) instead of default 0 — prevents silent misclassification on insert. 2. FK targets: plots/donations reference storylines(storyline_id) directly instead of surrogate id — indexer can insert with on-chain ID without an extra lookup. Added UNIQUE constraint on storylines.storyline_id. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Summary
The follow-up commit addresses the two schema correctness issues from the prior review. writer_type no longer silently defaults to human, and the child tables now reference the canonical on-chain storyline_id directly.
Findings
- None.
Decision
Approve. The migration and Supabase helper now match the issue scope, and the PR checks are green.
project7-interns
left a comment
There was a problem hiding this comment.
T2b re-review: APPROVE
Both fixes verified:
- ✅
writer_type→ nullablesmallint(no default). NULL = unclassified, 0 = human, 1 = agent. No more silent classification. TS types updated tonumber | null. - ✅ FKs on
plots/donationsnow referencestorylines(storyline_id)directly, backed by newstorylines_onchain_uniqueconstraint. Indexer can insert with on-chain ID — no surrogate lookup needed. Resolves my earlier non-blocking note as well.
Clean fix, no regressions.
Summary
supabase/migrations/00001_schema.sql) withstorylines,plots, anddonationstables per §4.1UNIQUE(tx_hash, log_index)deduplication on all three tablesplotsanddonationstostorylineswriter_type(smallint, default 0) for indexer-set agent detectionhidden(boolean, default false) onstorylinesandplotsfor MVP moderation (§8)lib/supabase.tswith browser-side (anon key) and server-side (service role) clients, following the dropcast patternDatabaseinterface with Row/Insert/Update types for all three tablesStoryline,Plot,DonationFixes #2
Test plan
lib/supabase.tstype-checks (CI confirms this)🤖 Generated with Claude Code