[#233] Add contract_address column for multi-contract support#234
[#233] Add contract_address column for multi-contract support#234realproject7 merged 3 commits intomainfrom
Conversation
Migration: - Added contract_address TEXT NOT NULL to all 6 tables - Existing rows default to old contract (0x05c4...b474) - Default changed to '' after backfill (indexers pass explicitly) TypeScript types: - Added contract_address to all Row/Insert/Update types Indexer routes (stamp on insert): - storyline, plot, donation indexers: contract_address in upsert rows - views API: contract_address on page_views insert - comments API: contract_address on comment insert - ratings API: contract_address on ratings upsert Frontend queries (filter by STORY_FACTORY): - Home page, story page, plot detail, OG route - Writer dashboard, reader dashboard, chain page - Ranking (trending/rising), ReaderPortfolio - All API GET handlers All queries use STORY_FACTORY.toLowerCase() from constants.ts. Switching NEXT_PUBLIC_CONTRACT_ADDRESS instantly shows only new contract data while preserving old data. Fixes #233 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: REQUEST CHANGES
Summary
Most read/write paths were updated for contract_address, but the cron backfill path still writes storylines, plots, and donations without stamping the new column. That leaves a correctness gap in the indexing pipeline and breaks the multi-contract isolation this PR is supposed to establish.
Findings
- [high] Backfill route still inserts rows without
contract_address- File:
src/app/api/cron/backfill/route.ts:210 - File:
src/app/api/cron/backfill/route.ts:234 - File:
src/app/api/cron/backfill/route.ts:271 - File:
src/app/api/cron/backfill/route.ts:302 - Suggestion: stamp
contract_address: STORY_FACTORY.toLowerCase()on every backfill upsert, just like the live indexer routes. Right now these inserts rely on the DB default, which this migration intentionally changes to ``, so any reindexed/backfilled rows will be written unscoped and then disappear from the newly filtered frontend queries.\n\n### Decision\nRequesting changes because #233 is an infra isolation fix, and leaving the backfill pipeline untagged would keep producing rows that violate the new contract-scoping model.
- File:
Stamps contract_address: STORY_FACTORY.toLowerCase() on all 4 insert objects in the backfill route (storyline, genesis plot, chained plot, donation). Addresses T2a review feedback on PR #234. 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 change fixes the remaining correctness gap by stamping contract_address on all cron backfill inserts, bringing the backfill path in line with the live indexers and the new frontend filtering model. The multi-contract isolation work now looks internally consistent across migration, types, reads, live writes, and backfill writes.
Findings
- None.
Decision
Approving because the previously blocking backfill hole is resolved and GitHub lint-and-typecheck passes on the updated head.
…edup, RPC scope - Bug 1: Fix migration default to match current STORY_FACTORY address - Bug 2: Add contract_address to ratings upsert onConflict - Bug 3: Add contract_address filter to view dedup query - Bug 4: Scope increment_view_count RPC to contract_address - Add unique index, performance indexes, and required Insert types Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
contract_address TEXT NOT NULLon all 6 tables, existing rows default to old contractcontract_addressto all Row/Insert/Update typescontract_address: STORY_FACTORY.toLowerCase().eq("contract_address", STORY_FACTORY.toLowerCase())Test plan
npx tsc --noEmitpasses (verified)Fixes #233
🤖 Generated with Claude Code