Old Convex schema → new D1 schema: is it an improvement?
Measured on 2026-11-18 from server/convex/schema.ts (frozen) and
backend/migrations/*.sql (new). Numbers are counted from the files, not remembered.
| Dimension | Convex (old) | D1 (new) | Verdict |
|---|---|---|---|
| Tables | 42 | 47 (43 product + 4 Better Auth) | more, but fewer overlapping concepts |
| Indexes | 136 (3.2/table) | 32 | fewer; composite FKs and PKs carry the paths |
| Foreign keys enforced | 0 | 25 | win |
UNIQUE constraints | 0 (Convex has no unique index) | 30 | win |
CHECK constraints | 0 | 64 | win |
NOT NULL columns | 0 (every field is v.optional by default) | 293 | win |
| Untyped holes | 17 × v.any() | 12 × TEXT -- JSON | marginal win |
| Ownership checks | 27 × userId + manual check in every mutation | composite FK (id, owner_id) + 4 triggers | win |
| Erasure model | none | ops_table_policy (one row/table, enforced by test) | win |
| Migration history | Convex handles it | ops_migrations ledger, files run at most once | win |
What was consolidated (fewer concepts, not fewer features)
| Old | New | Why it is better |
|---|---|---|
jobs + cachedJobs | corpus_jobs + corpus_job_sources | one posting = one row (UNIQUE(canonical_url)), N sources per posting; fingerprint + merged_into_id make dedupe/merge explicit instead of implicit |
jobMatchResults | columns on search_results (score, matched_by, explanation) | a match only exists inside a search; UNIQUE(search_id, job_id) stops duplicate rows |
emailSyncState | columns on email_accounts (sync_cursor, last_sync_at, last_sync_status/error) | 1:1 data stops needing its own table |
dailyUsage + rateLimits | ops_cap_quota + ops_cap_ledger | append-only charges with UNIQUE(owner_id, op_key) → a double click cannot charge twice; CHECK (used <= limit_value) is a database backstop on 5 applies / 50 emails |
companies, ycIndexShards | corpus_companies, corpus_yc_companies (+ company_notes) | companies are entities with a domain key, not index shards |
users | auth_user (Better Auth) | one identity source instead of a hand-rolled table + adapter |
salary: v.any() | 5 bounded fields in salary JSON | no untyped bag |
| — | blobs, email_draft_attachments, outreach_suppressions, ops_outbox, ops_consumer_deliveries, ops_dlq_incidents, profile_links | R2 map, attachments, suppression list and delivery honesty had no home before |
What was dropped, and whether it matters
| Old table | Status | Cost |
|---|---|---|
proxyProviders, proxyEndpoints, proxyAssignments, browserSessions | dropped | proxy pool and browser sessions now live in the scraper process (env + registry), not the product DB. No per-request proxy accounting in the DB — acceptable, it was telemetry |
logLines | dropped | log viewer is memory-only (dev.sh); there is no durable log table any more. Real loss if log history is ever needed |
outreachCampaigns | dropped | nothing in app/src reads a campaign (only utm.ts mentions the word). No user-facing loss found |
emailSyncState | folded into email_accounts | none |
What got worse
- No interactive transactions. D1 gives
db.batch()and single statements only; multi-table invariants must be triggers or batched guarded statements. Convex gave atomic multi-document mutations. This is the biggest ergonomic regression. - 12
TEXT -- JSONcolumns remain (links,skills,experience,education,achievements,work_authorization,other_urls,dossier,salary,scopes, …). Same class of hole asv.any(), just fewer and named — a comment is not a constraint. - Index count fell 136 → 32. Composite FKs and PKs cover the ownership joins, but any new query path needs an index added deliberately (
EXPLAIN QUERY PLANbefore shipping), where Convex's index-per-access-pattern habit hid that cost. - D1 limits are real: 100 columns/table, 2 MB row, 100 bound params, 30 s query, 10 GB DB.
- Same-name drift: the two schemas use different naming (
canonicalUrlvscanonical_url). The shared record inscrapers/contracts/job-record.schema.jsonis snake_case and the Convex edge maps, so this only bites anyone reading both files side by side.
Answer
Yes — materially, on the things that cost money or leak data. Uniqueness, requiredness, ownership and caps are now enforced by the database instead of by discipline in handlers: a second send cannot be charged twice, a search result cannot point at another owner's search, and used <= limit_value cannot be violated by an application bug. The residual free-form columns and the loss of interactive transactions are the honest costs, and neither is new debt created here — the first existed in Convex as v.any(), the second is D1's platform model.