Email for professionals and teams
Repository agent instructions
Database schema changes: update every dialect
Mailflare runs on SQLite/D1, PostgreSQL and MySQL from one schema file. Any change to src/db/schema/index.ts (table, column, index, default) must ship a migration for all three dialects in the same change:
npm run db:generate→drizzle/migrations/(SQLite/D1)npm run db:generate:pg→drizzle/migrations-pg/(PostgreSQL)npm run db:generate:mysql→drizzle/migrations-mysql/(MySQL/MariaDB)npm run db:bundleto refreshsrc/lib/migrations/bundle*.json(commit them).- Touching
messages,folders,mailboxesormailbox_aliasesbehaviour that SQLite does with triggers (JMAP change log,trashed_at, search index): add the equivalent trigger SQL to a new hand-written PostgreSQL and MySQL migration too. - Run
node --test tests/*.test.mjs(tests/database-dialects.test.mjsfails if the dialects diverge or a bundle is stale) and, if a database is available,npm run db:smoke -- <DATABASE_URL>.
Raw SQL must also work on all three dialects; see "The database is D1 unless DATABASE_URL says otherwise" in CLAUDE.md and docs/databases.md. Never edit an already-applied migration; add a new one.
Database backup and restore
- Whenever a migration creates, renames, or removes a persisted table, update the backup and restore table lists in the same change, even if the feature is unrelated to backups. Review
BACKUP_TABLESandINTERNAL_TABLESinsrc/lib/backups/export.ts,BACKUP_TABLE_GROUPSinsrc/lib/backups/table-groups.ts, andDatabaseBackupTableinsrc/lib/backups/types.d.ts. - Put every backed-up table in exactly one group. Keep
BACKUP_TABLESin foreign-key dependency order so restore inserts parents before children and deletes them in reverse order. Exclude a table only when its contents are derived or internally managed, and document why. - When adding a table, check backup and restore behavior both before and after its migration is applied. Keep older full backup documents restorable.