Cloudflare D1
Create a D1 database, apply local and remote migrations, and bind it to a Worker.
Use D1 when deploying Heyo Status to Cloudflare Workers. Start with
create-heyo-status --deployment cloudflare --database d1. The generated
project includes a migrations/ folder, a Worker, framework routes and a D1
binding declaration. You still need to create the remote database and replace
its placeholder ID. This page covers D1; follow the
Cloudflare deployment guide
for the complete setup.
1. Create and bind the database
From the generated project's root, run (replace my-status-page with your
project's database name):
Copy the returned database_id into wrangler.jsonc. Keep binding: "DB"
and migrations_dir: "migrations": the generated Worker reads env.DB, and
Wrangler reads numbered SQL files from migrations/.
The creator copies 0000_initial.sql through
0004_subscriber_uniqueness.sql into that folder. You don't need to write
the first migration yourself.
2. Migrate the local database
This generated script calls wrangler d1 migrations apply my-status-page --local. bun dev runs the same script before starting the framework
development server with a local D1 binding, so you can skip the separate
command if you're going straight into development. Local D1 data is separate
from the remote database; this step does not prepare production.
3. Migrate the remote database before deploying
Run the remote migration again whenever you add a numbered SQL file. Wrangler skips migrations it has already applied. To check that the schema exists in the remote database, for example:
Updating @heyo-sh/heyo-status does not update the generated
project's migrations/ directory. When a release adds migrations,
bring the new numbered SQL files from the matching generator release into
your project, review them, and apply them to local and remote D1 before
deploying the new runtime.
Wrangler tracks SQL files applied with wrangler d1 migrations apply in its
own migration history. The adapter's database.migrate() method uses
__heyo_status_migrations instead. Choose one approach for a database;
the generated Worker uses Wrangler, and request handlers do not migrate
on their own. Don't run heyo-status db migrate in a local shell for D1:
that shell has no Worker binding.
How the Worker gets env.DB
A D1 binding exists during a Worker request, not while your config is being
imported by build tools. The generated heyo-status.config.ts wraps
d1(binding) in lazyStatusDatabase(). The Worker supplies the binding before
serving production requests and scheduled events; the generated framework dev
routes supply the local binding in bun dev. Keep both paths if you change
the integration. bun run start builds and serves the actual Worker locally.
Running an unconfigured, standalone framework server without these bindings
cannot access D1.
For reference, the generated config resolves the binding lazily:
On Workers, use HTTP or DNS monitors. TCP and TLS checks require node:net
or node:tls, which Workers do not provide. See
Deploy to Cloudflare for
the full Worker setup.