You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,25 @@ When adding a new user-configurable setting:
90
90
91
91
## Database
92
92
93
-
- This project has three database backends: SQLite, PostgreSQL, and MySQL. When modifying migrations or schema, always update ALL three backend baseline migrations consistently. Check column names, table names, and constraints match across all backends.
93
+
- This project has three database backends: SQLite, PostgreSQL, and MySQL.
94
+
- Schema definitions live in `src/db/schema/` — one file per domain, with separate table definitions per backend (SQLite/PostgreSQL/MySQL).
95
+
- When modifying schema, ensure column names and types are consistent across all three backend definitions.
96
+
97
+
### Migration Registry System
98
+
99
+
Migrations use a centralized registry in `src/db/migrations.ts`. Each migration is registered with functions for all three backends.
-`export async function runMigrationNNNPostgres(client)` for PostgreSQL
105
+
-`export async function runMigrationNNNMysql(pool)` for MySQL
106
+
2. Register it in `src/db/migrations.ts` with `registry.register({ number, name, settingsKey, sqlite, postgres, mysql })`
107
+
3. Update `src/db/migrations.test.ts` (count, last migration name)
108
+
4. Make migrations **idempotent** — use try/catch for SQLite (`duplicate column`), `IF NOT EXISTS` for PostgreSQL, `information_schema` checks for MySQL
109
+
5.**Column naming**: SQLite uses `snake_case`, PostgreSQL/MySQL use `camelCase` (quoted in PG raw SQL)
**Problem**: The old migration system required adding migration calls in 3 separate places in `database.ts` (SQLite init, Postgres init, MySQL init), which was error-prone and hard to maintain.
666
+
667
+
**Solution**: Centralized `MigrationRegistry` in `src/db/migrations.ts`. Each migration is registered once with functions for all three backends.
668
+
669
+
**Architecture**:
670
+
```
671
+
src/db/
672
+
migrations.ts # Registry barrel - imports and registers all migrations
673
+
migrationRegistry.ts # MigrationRegistry class (runner logic)
0 commit comments