Roberto dac1d50b02 refactor: replace hand-rolled DB migrations with Drizzle migrator
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>
2026-05-08 15:11:52 +02:00
2026-03-16 08:53:08 +01:00
2026-04-15 11:44:40 +02:00
2026-04-15 11:44:40 +02:00
2026-04-15 11:44:40 +02:00
Description
No description provided
7.6 MiB
Languages
TypeScript 97.9%
CSS 2%