Schema and migrations
Which migrations to run for SQLite, D1 and PostgreSQL, and what they create.
The migration command depends on the database. Run it against the same database your deployed app uses, before serving requests with a new Heyo Status version:
| Database | Local development | Before deploying / after an upgrade |
|---|---|---|
| SQLite | Automatic when the adapter is created. | Back up the persistent file; starting the updated app applies new migrations. |
| Cloudflare D1 | bun run db:migrate in a generated project (or bun dev). | bunx wrangler d1 migrations apply <database-name> --remote, then deploy. |
| PostgreSQL | bun run db:migrate once the database is reachable. | Run bun run db:migrate with production database credentials, then deploy. |
bun run db:migrate is a script in generated projects. Follow the
SQLite,
D1 or
PostgreSQL guide to manage
the generated project's database. D1's local migration command does not
touch its remote database. Runtime request handlers don't migrate
PostgreSQL or D1 for you.
What gets created?
| Migration | Change |
|---|---|
0000_initial | status_results (individual checks) and status_daily_summaries (compacted history). |
0001_incidents_maintenance | incidents, incident_updates and maintenance_windows. |
0002_notification_log | Delivery attempt history. |
0003_subscribers | Email and webhook subscriptions. |
0004_subscriber_uniqueness | Removes duplicate subscriber destinations, then adds a unique index on (type, target). |
0004_subscriber_uniqueness deletes duplicate subscriber rows if you
upgrade an existing database with duplicates. Back up and review the data
before running it in production. Migrations add to the existing schema;
you should not recreate the database to upgrade.
These are the main tables after migration:
| Table | Stores |
|---|---|
status_results | Each monitor check, its outcome, latency and timestamp. |
status_daily_summaries | Compacted counts, downtime and latency per monitor and UTC day. |
incidents, incident_updates | Incident state and timeline. |
maintenance_windows | Planned work and affected monitors. |
notification_log | Delivery results, not webhook credentials or payloads. |
subscribers | Destinations and confirmation state. |
Timestamps are stored as epoch milliseconds. The database schema is not
created by Drizzle's migration CLI: Heyo Status supplies its own migrations.
Don't copy only a CREATE TABLE snippet from this page; use the migration
workflow for your adapter.
How are applied migrations tracked?
SQLite and the programmatic PostgreSQL adapter record applied IDs in
__heyo_status_migrations. They skip those IDs on subsequent runs. A
programmatic D1 database.migrate() call uses that table too, but generated
Cloudflare projects use Wrangler to apply SQL from migrations/. Wrangler
keeps its own migration history; it does not mark IDs in
__heyo_status_migrations. Don't alternate between Wrangler and
database.migrate() on the same D1 database.
The generator copies D1 SQL files into the project when it creates it.
Updating the runtime package does not copy any newly added SQL files into
an existing project. On upgrade, add new numbered SQL files from the matching
generator release to migrations/, then run Wrangler's local and remote
migration commands before deploying the updated runtime.
Using a custom database adapter
If none of the built-in adapters fit, pass an implementation of
StatusDatabaseAdapter as database. The type is exported from
@heyo-sh/heyo-status/types. Your adapter must implement the full contract,
including check history, incidents, maintenance, subscribers and the
notification log; configuration rejects incomplete adapters.
Heyo Status doesn't create tables for a custom adapter. Provide your own
migration process. To let heyo-status db migrate invoke it, expose an
optional migrate(): Promise<void> method; otherwise don't treat the CLI's
"embedded migrations" message as proof that your schema exists.
For a database that can only be opened after a request binding or secret
becomes available, wrap its construction in lazyStatusDatabase(). Its
migrate() forwards to the resolved adapter, but throws if that adapter
has no migration method.