mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-17 13:21:31 +00:00
1.9 KiB
1.9 KiB
Phase 01 — D1 Setup — Implementation Report
Files Created
src/db/sql-store-interface.js— JSDoc typedefs for SqlStore/SqlRunResultsrc/db/cf-sql-store.js— CFSqlStore class wrapping env.DB prepare/run/all/first/batchsrc/db/create-sql-store.js— factory; returns null when env.DB absent, SqlStore otherwise; exposes tablePrefixtests/fakes/fake-d1.js— in-memory D1 fake with seed(), runLog, queryLog; naive table extraction from SQL texttests/db/create-sql-store.test.js— 13 tests: validation, tablePrefix, run/all/first/batch round-tripsscripts/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; passessql: createSqlStore(mod.name, env)into init alongside dbwrangler.toml— added d1_databases block; database_id = REPLACE_ME_D1_UUID (requires manual fill afterwrangler 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.basenameimport 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.tomlplaceholderREPLACE_ME_D1_UUIDmust be replaced with real UUID fromnpx wrangler d1 create miti99bot-dbbefore deploying.- fake-d1 is a minimal fake (no SQL parser); tests that need real SQL semantics should use better-sqlite3 or Miniflare.