Database Management
The aw db CLI commands manage the supported Allowealth database targets:
sqlitefor local developmentd1for remote Cloudflare D1d1-localfor Wrangler-managed local D1 state
Supported Targets
Section titled “Supported Targets”| Target | Use Case | Configuration |
|---|---|---|
sqlite | Local development | db/.dev.db |
d1 | Remote Cloudflare D1 | .env.production + Wrangler |
d1-local | Local D1 emulation | Wrangler local state |
Migrations
Section titled “Migrations”Generate a migration
Section titled “Generate a migration”Create a migration from schema changes:
bun run aw db generateApply migrations
Section titled “Apply migrations”Apply pending migrations to the selected target:
# SQLite (default)bun run aw db migrate
# Remote D1bun run aw db migrate --target d1
# Local D1bun run aw db migrate --target d1-localSchema changes
Section titled “Schema changes”Quick development workflow
Section titled “Quick development workflow”Push schema changes directly to SQLite:
bun run aw db pushUse this only in development. It bypasses migration tracking.
Reset local SQLite
Section titled “Reset local SQLite”Delete the local SQLite database, recreate the schema, and seed demo data:
bun run aw db resetThis command works only with the sqlite target.
Backup
Section titled “Backup”Create timestamped backups for any supported target:
# SQLitebun run aw db backup --target sqlite
# Remote D1bun run aw db backup --target d1
# Local D1bun run aw db backup --target d1-localBy default, backups save to backups/<target>-<timestamp>.<ext>.
Use a custom path when needed:
bun run aw db backup --target sqlite --output /path/to/backup.dbRestore
Section titled “Restore”Restore validates backups before applying changes and creates a safety backup unless you opt out.
Dry run
Section titled “Dry run”Validate a backup without restoring it:
bun run aw db restore --target d1 --source cloud --dry-runRestore from local backup
Section titled “Restore from local backup”# Interactive (requires confirmation)bun run aw db restore --target sqlite
# Non-interactivebun run aw db restore --target sqlite --force
# Skip pre-restore backupbun run aw db restore --target sqlite --force --no-backup
# Restore a specific filebun run aw db restore --target sqlite --file backups/sqlite-2026-03-04.sqlRestore from cloud backup
Section titled “Restore from cloud backup”bun run aw db restore --target d1 --source cloudCloud backups read from backups/cloud/ by default. Override the location if needed:
bun run aw db restore --target d1 --source cloud --cloud-dir /path/to/cloud/backupsData seeding
Section titled “Data seeding”Seed demo data
Section titled “Seed demo data”bun run aw db seed --target sqliteControl data volume
Section titled “Control data volume”# Seed 6 months of historybun run aw db seed --target sqlite --months=6
# Seed 12 months + 5,000 extra transactionsbun run aw db seed --target sqlite --months=12 --transactions=5000Add benchmark data
Section titled “Add benchmark data”bun run aw db seed --target sqlite --benchmarkAdd stress-test data
Section titled “Add stress-test data”bun run aw db seed --target sqlite --stressDangerous operations
Section titled “Dangerous operations”Drop all tables
Section titled “Drop all tables”Delete all tables and reset the selected database:
# SQLitebun run aw db drop
# Remote D1bun run aw db drop --target d1
# Local D1bun run aw db drop --target d1-localThis command requires typed confirmation.
Empty data but keep schema
Section titled “Empty data but keep schema”bun run aw db emptyD1-specific operations
Section titled “D1-specific operations”Export a D1 database
Section titled “Export a D1 database”The backup command uses wrangler d1 export for D1 targets:
bun run aw db backup --target d1Restore a D1 database
Section titled “Restore a D1 database”The restore command uses wrangler d1 execute:
bun run aw db restore --target d1 --file backups/d1-2026-03-04.sqlQuality checks
Section titled “Quality checks”Before committing database changes, run:
bun run lint:fixbun run stylelint:fixbun run format:fixbun run typecheckSee also
Section titled “See also”- COMMANDS.md - Complete CLI reference
- Database Migrations - Migration workflow and patterns
- Feature Workflow - Implementation sequence for new features