Skip to content

[#233] Add contract_address column for multi-contract support#234

Merged
realproject7 merged 3 commits intomainfrom
task/233-contract-address
Mar 17, 2026
Merged

[#233] Add contract_address column for multi-contract support#234
realproject7 merged 3 commits intomainfrom
task/233-contract-address

Conversation

@realproject7
Copy link
Copy Markdown
Owner

Summary

  • Migration: contract_address TEXT NOT NULL on all 6 tables, existing rows default to old contract
  • Types: Added contract_address to all Row/Insert/Update types
  • Indexer inserts: All 6 routes stamp contract_address: STORY_FACTORY.toLowerCase()
  • Frontend queries: All reads filter by .eq("contract_address", STORY_FACTORY.toLowerCase())
  • 17 files changed across migration, types, indexers, pages, components, and ranking

Test plan

  • Run migration on Supabase
  • Existing data tagged with old contract address
  • New storyline → contract_address matches current STORY_FACTORY
  • Home page only shows current contract's data
  • Story pages filter correctly
  • Writer/reader dashboards filter correctly
  • Ratings, comments, views all scoped to contract
  • npx tsc --noEmit passes (verified)

Fixes #233

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@realproject7 realproject7 merged commit 860e253 into main Mar 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Infra] Add contract_address column for multi-contract support

2 participants