FORGE-89: generated sqlite-core (D1) schema with a DDL parity test #721
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gmackie/ForgeGraph!721
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "FORGE-89-sqlite-schema"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
FORGE-89 (D1 Phase 4, parent FORGE-69), step 1 of 5: the sqlite-core schema and its parity test.
What
packages/db/src/schema-sqlite/: drizzle sqlite-core tables for all 142 Postgres tables, plus enum compat exports (fooEnum.enumValues), constants, type re-exports and relations, so the module exports exactly the same names as@forgegraph/db/schema.packages/db/scripts/generate-sqlite-schema.ts(pnpm --filter @forgegraph/db db:sqlite:generate,db:sqlite:check). It reads drizzle's own table metadata (getTableConfig, relations), so it handles this schema's standalone-call style thatscripts/pg-to-d1.mjscannot, and it fails on anything it can't translate (unknown column types, Postgres-only SQL in checks/indexes, unlisted default functions, serial columns without a unique-index entry).text({ enum })+CHECK (col IN (...))from the shared@forgegraph/db/enumsarrays; json/jsonb/arrays →text({ mode: "json" })typed as the pg column; timestamptz →integer({ mode: "timestamp_ms" })with an epoch-ms SQL default fordefaultNow(); boolean →integer({ mode: "boolean" }); serialdeployment_events.seq→ integer +deployment_event_seq_unique_idx(same name as FORGE-85 #712; skipped once #712 adds it on Postgres); numeric/real → real; the 7 partial and 3 expression indexes, checks (btrim→trim) and all 255 FKs with their actions are kept.schema-sqlite/ddl.ts: drizzle-kit DDL with every table madeSTRICT(wrong storage classes fail at write time; PK columns are NOT NULL). The D1 test lane (next PR) and the Phase 5 baseline reuse it.schema-sqlite/parity.test.ts(runs in the existing unit-web lane): fails if the generated files are stale, then loads the DDL into a real SQLite (node:sqlite) and compares PRAGMAtable_info/index_list/index_xinfo/foreign_key_listand the stored CHECKs against the Postgres metadata: tables, columns, storage types, nullability, DB defaults, PKs, unique columns, FKs + actions, indexes (unique, columns, expression text, partial predicate) and checks. Also checks CHECK/STRICT/NOT NULL enforcement on a real row.tsx(packages/db) andminiflare(packages/api, same version wrangler already pins; used by the next PR) to devDependencies; lockfile edited for the two importers only.Verification
pnpm --filter @forgegraph/db test: 250 passed (148 parity cases).pnpm --filter @forgegraph/db typecheck: clean.db:sqlite:check: up to date.deploymentsDDL parity case.Follow-ups in this issue: D1 test DB behind the test helpers (FG_TEST_DB=d1), a non-required CI lane with a known-failures list, the remote D1 feature probe, and the staging cron.
🤖 Generated with Claude Code
4d40c5ac0ba29afd2f36