Skip to content

Database Management

The aw db CLI commands manage the supported Allowealth database targets:

  • sqlite for local development
  • d1 for remote Cloudflare D1
  • d1-local for Wrangler-managed local D1 state
TargetUse CaseConfiguration
sqliteLocal developmentdb/.dev.db
d1Remote Cloudflare D1.env.production + Wrangler
d1-localLocal D1 emulationWrangler local state

Create a migration from schema changes:

Terminal window
bun run aw db generate

Apply pending migrations to the selected target:

Terminal window
# SQLite (default)
bun run aw db migrate
# Remote D1
bun run aw db migrate --target d1
# Local D1
bun run aw db migrate --target d1-local

Push schema changes directly to SQLite:

Terminal window
bun run aw db push

Use this only in development. It bypasses migration tracking.

Delete the local SQLite database, recreate the schema, and seed demo data:

Terminal window
bun run aw db reset

This command works only with the sqlite target.

Create timestamped backups for any supported target:

Terminal window
# SQLite
bun run aw db backup --target sqlite
# Remote D1
bun run aw db backup --target d1
# Local D1
bun run aw db backup --target d1-local

By default, backups save to backups/<target>-<timestamp>.<ext>.

Use a custom path when needed:

Terminal window
bun run aw db backup --target sqlite --output /path/to/backup.db

Restore validates backups before applying changes and creates a safety backup unless you opt out.

Validate a backup without restoring it:

Terminal window
bun run aw db restore --target d1 --source cloud --dry-run
Terminal window
# Interactive (requires confirmation)
bun run aw db restore --target sqlite
# Non-interactive
bun run aw db restore --target sqlite --force
# Skip pre-restore backup
bun run aw db restore --target sqlite --force --no-backup
# Restore a specific file
bun run aw db restore --target sqlite --file backups/sqlite-2026-03-04.sql
Terminal window
bun run aw db restore --target d1 --source cloud

Cloud backups read from backups/cloud/ by default. Override the location if needed:

Terminal window
bun run aw db restore --target d1 --source cloud --cloud-dir /path/to/cloud/backups
Terminal window
bun run aw db seed --target sqlite
Terminal window
# Seed 6 months of history
bun run aw db seed --target sqlite --months=6
# Seed 12 months + 5,000 extra transactions
bun run aw db seed --target sqlite --months=12 --transactions=5000
Terminal window
bun run aw db seed --target sqlite --benchmark
Terminal window
bun run aw db seed --target sqlite --stress

Delete all tables and reset the selected database:

Terminal window
# SQLite
bun run aw db drop
# Remote D1
bun run aw db drop --target d1
# Local D1
bun run aw db drop --target d1-local

This command requires typed confirmation.

Terminal window
bun run aw db empty

The backup command uses wrangler d1 export for D1 targets:

Terminal window
bun run aw db backup --target d1

The restore command uses wrangler d1 execute:

Terminal window
bun run aw db restore --target d1 --file backups/d1-2026-03-04.sql

Before committing database changes, run:

Terminal window
bun run lint:fix
bun run stylelint:fix
bun run format:fix
bun run typecheck