Skip to content

3. Create the database (D1)

The app stores everything (people, schedule, holidays, time off, users) in a Cloudflare D1 database. D1 is a SQLite database that lives in your Cloudflare account. You create it once.

It may already exist

The project's wrangler.toml already contains a database_id. If that database still exists in this Cloudflare account, you can skip creating a new one and just confirm the ID matches (see the bottom of this page). Create a new one only if you're setting up a fresh Cloudflare account.

Create the database

In the oncall-scheduler folder, run:

npx wrangler d1 create oncall_db

Wrangler prints a short block of text that includes a database_id — a long string that looks like:

database_id = "49779816-efaf-456f-9cb1-1d06cead7292"

Copy that whole database_id value. You need it in the next step.

Paste the ID into wrangler.toml

  1. Open the file wrangler.toml in the oncall-scheduler folder with any text editor (Notepad is fine).
  2. Find the section that looks like this:

    [[d1_databases]]
    binding = "DB"
    database_name = "oncall_db"
    database_id = "PASTE-YOUR-ID-HERE"
    
  3. Replace the value after database_id = with the ID you just copied (keep the quotes).

  4. Save the file.

The binding name must stay DB

Don't change binding = "DB" — the app's code looks for a binding called DB. Only change the database_id.

What this file does

wrangler.toml is the app's configuration. The important parts:

name = "oncall-scheduler"
compatibility_date = "2025-06-01"
pages_build_output_dir = "client/dist"

[[d1_databases]]
binding = "DB"
database_name = "oncall_db"
database_id = "…your id…"

[vars]
APP_ENV = "production"
DEFAULT_SCHEDULE_WEEK_START = "wednesday"
ADMIN_EMAILS = "robertbettencourt@totlcom.com"
  • pages_build_output_dir tells Cloudflare where the built website ends up.
  • [[d1_databases]] connects the app to your database.
  • [vars] holds non-secret settings — covered on the Environment variables page.

You won't create the tables yet — that happens in Run database migrations, after the project is connected to Cloudflare. For now, you just need the database to exist and its ID to be in wrangler.toml.

Confirm the database exists

npx wrangler d1 list

You should see oncall_db in the list.

Put the code on GitHub