FORGE-89: remote D1 feature probe (scripts/d1-feature-probe.ts) #733

Merged
gmackie merged 1 commit from FORGE-89-d1-feature-probe into main 2026-10-12 06:45:49 +00:00
Owner

FORGE-89 (D1 Phase 4), step 4 of 5. Stacked on #721 (uses schema-sqlite/ddl.ts); review the top commit.

What

scripts/d1-feature-probe.ts creates a scratch D1 database, runs the SQL features and limits the D1 port depends on through a real remote binding (wrangler getPlatformProxy with remote: true, so prepare/bind/batch are the Worker binding's semantics, not the REST API's), prints a report, and deletes the database (--keep to keep it, --json out.json for the raw results).

Credentials: wrangler's own resolution, i.e. the local wrangler login (OAuth with d1 + workers_scripts write), or CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID exported from ForgeGraph's workspace Cloudflare integration (getCloudflareConfig). This run used the local wrangler login on account c07a7e704db1808e1fff91bed2b1cd49.

Run: pnpm exec tsx scripts/d1-feature-probe.ts from the repo root.

Results against remote D1 (2026-10-12T06:12:44.007Z, scratch DB fg-d1-probe-20261012061156, deleted afterwards: wrangler d1 list shows no fg-d1-probe-*)

Probe Result Detail
setup tables (STRICT) pass 9 DDL statements in one batch (378 ms)
RETURNING (insert, upsert, update, delete) pass insert 4 rows, upsert 1, update 2, delete 1 (1063 ms)
default (unixepoch('subsec') * 1000) epoch-ms pass created_at within 991 ms of the client clock (262 ms)
window functions (row_number, lag, sum over) pass latest-per-group ids [2,4] (201 ms)
ORDER BY ... NULLS FIRST / NULLS LAST pass asc nulls first [null,4,11,12]; desc nulls last [12,11,4,null] (474 ms)
aggregate FILTER (WHERE ...) pass {"a":2,"nulls":1,"total":4} (325 ms)
json_each IN-expansion past the 100-parameter limit, ->> and json_extract pass 500 ids in one bound JSON array matched 4 rows; ->> and json_extract ok (520 ms)
partial unique index (where active = 1) pass inactive duplicate allowed; active duplicate rejected: D1_ERROR: UNIQUE constraint failed: p.k: SQLITE_CONSTRAINT (extended: SQLITE_CON (739 ms)
expression unique index (lower(h)) pass case-insensitive duplicate rejected: D1_ERROR: UNIQUE constraint failed: index 'e_lower_h': SQLITE_CONSTRAINT (extend (541 ms)
batch atomicity on a mid-batch constraint failure pass batch failed (D1_ERROR: UNIQUE constraint failed: u.k: SQLITE_CONSTRAINT (extended: SQLITE_CON) and left 0 rows (556 ms)
conditional write guard: INSERT ... SELECT max(seq) + 1 pass 5 inserts in one batch got seq [1,2,3,4,5] (775 ms)
foreign keys enforced, ON DELETE CASCADE, PRAGMA defer_foreign_keys in a batch pass FK violation rejected (D1_ERROR: FOREIGN KEY constraint failed: SQLITE_CONSTRAINT (); child-before-parent batch ok with defer_foreign_keys; cascade ok (1049 ms)
explicit BEGIN / SAVEPOINT rejected (error 7500) pass BEGIN: D1_ERROR: To execute a transaction, please use the state.storage.transaction() or state.storage.transactionSync() APIs i \| SAVEPOINT: D1_ERROR: To execute a transaction, please use the state.storage.transaction() or state.storage.transactionSync() APIs i (250 ms)
bound-parameter limit (100 ok, 101 rejected) pass 100 parameters ok; 101: D1_ERROR: too many SQL variables at offset 307: SQLITE_ERROR \| too many SQL variables at offset 307: (474 ms)
SQL statement length limit (~100 KB) pass 99,000-byte statement ok; 101,000 bytes: D1_ERROR: statement too long: SQLITE_TOOBIG \| statement too long: SQLITE_TOOBIG (559 ms)
row / string size limit (documented 2 MB) pass largest accepted text value 8 MB; first failure: 16 MB: D1_ERROR: string or blob too big: SQLITE_TOOBIG \| string or blob too big: SQLITE_TOOBIG (19165 ms)
response size (rows of 1.9 MB generated server side) pass largest successful read 40 rows (~76 MB); first failure: none up to 41 rows (~78 MB) (3893 ms)
generated ForgeGraph schema loads (STRICT, 142 tables) pass 527 statements, 142 tables; enum CHECK rejects bad value (D1_ERROR: CHECK constraint failed: registry_packages_analysi) (5857 ms)

18/18 passed. Findings that matter for the port:

  • Everything the design relies on works remotely: RETURNING (including upsert), window functions, NULLS FIRST/LAST, FILTER, json_each IN-expansion (500 ids in one bound parameter), ->>, partial and expression unique indexes, INSERT … SELECT max(seq)+1 inside one batch (the FORGE-85 seq assignment), FKs with cascades, and PRAGMA defer_foreign_keys inside a batch (the Phase 5 copy tool's plan).
  • Batch atomicity confirmed: a UNIQUE violation in the 2nd of 3 statements fails the batch and leaves 0 rows.
  • BEGIN and SAVEPOINT are rejected remotely. Through the binding the error text is the Durable Objects message ("To execute a transaction, please use the state.storage.transaction() …"), not a literal "7500". The test-lane guard (#725) rejects them regardless of text.
  • Limits: 100 bound parameters (101 → "too many SQL variables"); a statement of about 100 KB (99,000 bytes ok, 101,000 → SQLITE_TOOBIG). Values are more generous than the documented 2 MB row limit: 8 MB was accepted, 16 MB failed with "string or blob too big". Treat 2 MB as the design limit anyway. No response-size limit was hit reading 40 rows of 1.9 MB (~76 MB).
  • The full generated ForgeGraph schema (527 statements, 142 STRICT tables) loads on remote D1, and its enum CHECKs reject bad values.

🤖 Generated with Claude Code

FORGE-89 (D1 Phase 4), step 4 of 5. **Stacked on #721** (uses `schema-sqlite/ddl.ts`); review the top commit. ## What `scripts/d1-feature-probe.ts` creates a scratch D1 database, runs the SQL features and limits the D1 port depends on through a **real remote binding** (wrangler `getPlatformProxy` with `remote: true`, so `prepare/bind/batch` are the Worker binding's semantics, not the REST API's), prints a report, and deletes the database (`--keep` to keep it, `--json out.json` for the raw results). Credentials: wrangler's own resolution, i.e. the local `wrangler login` (OAuth with d1 + workers_scripts write), or `CLOUDFLARE_API_TOKEN` / `CLOUDFLARE_ACCOUNT_ID` exported from ForgeGraph's workspace Cloudflare integration (`getCloudflareConfig`). This run used the local wrangler login on account c07a7e704db1808e1fff91bed2b1cd49. Run: `pnpm exec tsx scripts/d1-feature-probe.ts` from the repo root. ## Results against remote D1 (2026-10-12T06:12:44.007Z, scratch DB `fg-d1-probe-20261012061156`, deleted afterwards: `wrangler d1 list` shows no `fg-d1-probe-*`) | Probe | Result | Detail | | --- | --- | --- | | setup tables (STRICT) | pass | 9 DDL statements in one batch (378 ms) | | RETURNING (insert, upsert, update, delete) | pass | insert 4 rows, upsert 1, update 2, delete 1 (1063 ms) | | default (unixepoch('subsec') * 1000) epoch-ms | pass | created_at within 991 ms of the client clock (262 ms) | | window functions (row_number, lag, sum over) | pass | latest-per-group ids [2,4] (201 ms) | | ORDER BY ... NULLS FIRST / NULLS LAST | pass | asc nulls first [null,4,11,12]; desc nulls last [12,11,4,null] (474 ms) | | aggregate FILTER (WHERE ...) | pass | {"a":2,"nulls":1,"total":4} (325 ms) | | json_each IN-expansion past the 100-parameter limit, ->> and json_extract | pass | 500 ids in one bound JSON array matched 4 rows; ->> and json_extract ok (520 ms) | | partial unique index (where active = 1) | pass | inactive duplicate allowed; active duplicate rejected: D1_ERROR: UNIQUE constraint failed: p.k: SQLITE_CONSTRAINT (extended: SQLITE_CON (739 ms) | | expression unique index (lower(h)) | pass | case-insensitive duplicate rejected: D1_ERROR: UNIQUE constraint failed: index 'e_lower_h': SQLITE_CONSTRAINT (extend (541 ms) | | batch atomicity on a mid-batch constraint failure | pass | batch failed (D1_ERROR: UNIQUE constraint failed: u.k: SQLITE_CONSTRAINT (extended: SQLITE_CON) and left 0 rows (556 ms) | | conditional write guard: INSERT ... SELECT max(seq) + 1 | pass | 5 inserts in one batch got seq [1,2,3,4,5] (775 ms) | | foreign keys enforced, ON DELETE CASCADE, PRAGMA defer_foreign_keys in a batch | pass | FK violation rejected (D1_ERROR: FOREIGN KEY constraint failed: SQLITE_CONSTRAINT (); child-before-parent batch ok with defer_foreign_keys; cascade ok (1049 ms) | | explicit BEGIN / SAVEPOINT rejected (error 7500) | pass | BEGIN: D1_ERROR: To execute a transaction, please use the state.storage.transaction() or state.storage.transactionSync() APIs i \\| SAVEPOINT: D1_ERROR: To execute a transaction, please use the state.storage.transaction() or state.storage.transactionSync() APIs i (250 ms) | | bound-parameter limit (100 ok, 101 rejected) | pass | 100 parameters ok; 101: D1_ERROR: too many SQL variables at offset 307: SQLITE_ERROR \\| too many SQL variables at offset 307: (474 ms) | | SQL statement length limit (~100 KB) | pass | 99,000-byte statement ok; 101,000 bytes: D1_ERROR: statement too long: SQLITE_TOOBIG \\| statement too long: SQLITE_TOOBIG (559 ms) | | row / string size limit (documented 2 MB) | pass | largest accepted text value 8 MB; first failure: 16 MB: D1_ERROR: string or blob too big: SQLITE_TOOBIG \\| string or blob too big: SQLITE_TOOBIG (19165 ms) | | response size (rows of 1.9 MB generated server side) | pass | largest successful read 40 rows (~76 MB); first failure: none up to 41 rows (~78 MB) (3893 ms) | | generated ForgeGraph schema loads (STRICT, 142 tables) | pass | 527 statements, 142 tables; enum CHECK rejects bad value (D1_ERROR: CHECK constraint failed: registry_packages_analysi) (5857 ms) | **18/18 passed.** Findings that matter for the port: - Everything the design relies on works remotely: RETURNING (including upsert), window functions, NULLS FIRST/LAST, FILTER, json_each IN-expansion (500 ids in one bound parameter), `->>`, partial and expression unique indexes, `INSERT … SELECT max(seq)+1` inside one batch (the FORGE-85 seq assignment), FKs with cascades, and `PRAGMA defer_foreign_keys` inside a batch (the Phase 5 copy tool's plan). - **Batch atomicity confirmed**: a UNIQUE violation in the 2nd of 3 statements fails the batch and leaves 0 rows. - **BEGIN and SAVEPOINT are rejected remotely**. Through the binding the error text is the Durable Objects message ("To execute a transaction, please use the state.storage.transaction() …"), not a literal "7500". The test-lane guard (#725) rejects them regardless of text. - **Limits**: 100 bound parameters (101 → "too many SQL variables"); a statement of about 100 KB (99,000 bytes ok, 101,000 → SQLITE_TOOBIG). Values are more generous than the documented 2 MB row limit: 8 MB was accepted, 16 MB failed with "string or blob too big". Treat 2 MB as the design limit anyway. No response-size limit was hit reading 40 rows of 1.9 MB (~76 MB). - The full generated ForgeGraph schema (527 statements, 142 STRICT tables) loads on remote D1, and its enum CHECKs reject bad values. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
FORGE-89: generated sqlite-core (D1) schema with a DDL parity test
All checks were successful
CI / gitleaks (pull_request) Successful in 20s
CF executor smoke / smoke (pull_request) Successful in 23s
CI / unit-api (pull_request) Successful in 2m37s
CI / unit-web (pull_request) Successful in 3m59s
CI / storybook (pull_request) Successful in 2m29s
CI / web-build (pull_request) Successful in 2m54s
CI / go (pull_request) Successful in 1m8s
CI / checks (pull_request) Successful in 3m3s
CI / database (pull_request) Successful in 3m41s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 39s
a29afd2f36
Adds packages/db/src/schema-sqlite/, a drizzle sqlite-core schema for all 142
tables, generated from the Postgres schema's drizzle metadata by
packages/db/scripts/generate-sqlite-schema.ts (pnpm --filter @forgegraph/db
db:sqlite:generate). Translation follows the D1 design doc: pgEnum -> text +
CHECK built from the shared @forgegraph/db/enums arrays, json/jsonb/arrays ->
text json typed as the pg column, timestamptz -> integer timestamp_ms with an
epoch-ms SQL default, boolean -> integer boolean, serial seq -> integer +
deployment_event_seq_unique_idx (FORGE-85), partial/expression indexes,
checks (btrim -> trim) and FK actions kept. Relations are generated too.

schema-sqlite/ddl.ts produces the DDL via drizzle-kit and makes every table
STRICT; the D1 test lane and the Phase 5 baseline reuse it. parity.test.ts
fails when the generated files are stale and compares the DDL that SQLite
actually builds (PRAGMA table_info / index_list / foreign_key_list) against
the Postgres metadata: tables, columns, types, nullability, defaults, PKs,
unique columns, FKs and actions, indexes incl. partial/expression, checks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
FORGE-89: scripts/d1-feature-probe.ts (remote D1 feature and limit probe)
All checks were successful
CI / gitleaks (pull_request) Successful in 16s
CI / unit-api (pull_request) Successful in 2m42s
CI / unit-web (pull_request) Successful in 3m0s
CI / storybook (pull_request) Successful in 1m59s
CI / go (pull_request) Successful in 1m27s
CI / web-build (pull_request) Successful in 2m55s
CI / checks (pull_request) Successful in 2m59s
CI / database (pull_request) Successful in 2m56s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 40s
b2974e0eb3
Creates a scratch D1 database, runs the features and limits the D1 port
relies on through a real remote binding (wrangler getPlatformProxy with
remote: true), prints a report and deletes the database. Covers RETURNING,
window functions, NULLS FIRST/LAST, aggregate FILTER, json_each
IN-expansion and ->>, partial and expression unique indexes, batch
atomicity on a mid-batch constraint failure, INSERT ... SELECT max+1,
FK enforcement with defer_foreign_keys and cascades, BEGIN/SAVEPOINT
rejection, the 100-parameter and statement-length limits, value and
response sizes, and loading the generated STRICT ForgeGraph schema.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.