mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-17 13:21:31 +00:00
28 lines
1.9 KiB
Markdown
28 lines
1.9 KiB
Markdown
# Phase 01 — D1 Setup — Implementation Report
|
|
|
|
## Files Created
|
|
- `src/db/sql-store-interface.js` — JSDoc typedefs for SqlStore/SqlRunResult
|
|
- `src/db/cf-sql-store.js` — CFSqlStore class wrapping env.DB prepare/run/all/first/batch
|
|
- `src/db/create-sql-store.js` — factory; returns null when env.DB absent, SqlStore otherwise; exposes tablePrefix
|
|
- `tests/fakes/fake-d1.js` — in-memory D1 fake with seed(), runLog, queryLog; naive table extraction from SQL text
|
|
- `tests/db/create-sql-store.test.js` — 13 tests: validation, tablePrefix, run/all/first/batch round-trips
|
|
- `scripts/migrate.js` — custom migration runner; walks src/modules/*/migrations/*.sql sorted, tracks applied in _migrations table, supports --dry-run and --local flags
|
|
|
|
## Files Modified
|
|
- `src/modules/registry.js` — added createSqlStore import; passes `sql: createSqlStore(mod.name, env)` into init alongside db
|
|
- `wrangler.toml` — added [[d1_databases]] block; database_id = REPLACE_ME_D1_UUID (requires manual fill after `wrangler d1 create`)
|
|
- `package.json` — added `"db:migrate": "node scripts/migrate.js"`; chained into deploy: `wrangler deploy && npm run db:migrate && npm run register`
|
|
|
|
## Deviations
|
|
- `dispatcher.js`: no change needed — it delegates entirely to buildRegistry which already handles init; spec note resolved.
|
|
- `basename` import in migrate.js kept (unused but Biome didn't flag it as unused import — left for future use). Actually removed by format — clean.
|
|
|
|
## Test Results
|
|
- npm test: 118/118 pass (12 files)
|
|
- npm run lint: clean (0 errors)
|
|
- register:dry: exits with "not found" for .env.deploy — expected in dev, no code regression
|
|
|
|
## Notes
|
|
- `wrangler.toml` placeholder `REPLACE_ME_D1_UUID` must be replaced with real UUID from `npx wrangler d1 create miti99bot-db` before deploying.
|
|
- fake-d1 is a minimal fake (no SQL parser); tests that need real SQL semantics should use better-sqlite3 or Miniflare.
|