dac1d50b021b84b7aa31bd64318307dff5e188d0
Drop the MIGRATION_SQL string + try/catch ALTER TABLE block from initDb() in favor of drizzle-orm/better-sqlite3/migrator, which reads src/main/db/migrations/ (the canonical drizzle-kit output) and applies each *.sql in order, tracked via __drizzle_migrations. This fixes a class of bugs where schema.ts + a generated migration ship correctly but db/index.ts is forgotten — most recently 0004 (estimate column + task_attachments table), which silently broke tasks.list on existing DBs. Migration folder resolution: - Packaged: <resourcesPath>/migrations (declared as extraResource in forge.config.ts so it lands next to the asar) - Dev: <appPath>/src/main/db/migrations (Vite bundles main into a single main.js, so __dirname is not next to the migrations folder) Bootstrap for legacy DBs: pre-existing DBs created by the old hand-rolled MIGRATION_SQL have all tables from 0000-0003 but no __drizzle_migrations ledger. We detect this on startup (tasks table present, ledger missing), seed the ledger marking all but the latest migration as applied, then let the migrator run only the new one. This preserves existing data and the migrator's hash check on subsequent runs. Verified locally: real user DB (51 tasks) migrated cleanly — estimate column added, task_attachments table created, all rows preserved. Future schema changes: edit schema.ts → npx drizzle-kit generate → commit. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
step 0.1 complete: Type-safe contracts for all backend communication and the batch/storage subsystem
Description
No description provided
Languages
TypeScript
97.9%
CSS
2%