Documentation

Database Development

Change the D1 schema and apply a reviewed migration

For initial setup, use Cloudflare D1. This page is for adding or changing tables after your site works.

Change a table

  1. Find the relevant schema in src/db/. Follow the existing SQLite column definitions and indexes.
  2. Ask your coding tool to update the corresponding queries in src/shared/model/ and service behavior in src/services/.
  3. Generate the migration:
pnpm db:generate
  1. Read the new SQL file in drizzle/. Check whether it removes columns, tables, or existing data. Back up production data before applying a destructive change.
  2. Apply the migration locally and verify the affected feature:
pnpm db:migrate:local
pnpm typecheck
pnpm test

After checking the local result, apply it to the intended production database:

pnpm exec wrangler d1 migrations apply shipstart-db --remote

Replace the database name if you renamed it. Deploy the application code together with the compatible schema change.

Useful files

PathPurpose
src/db/SQLite schema definitions
drizzle.config.tsMigration generation configuration
drizzle/SQL migrations and metadata
src/shared/model/Database queries
src/services/Application operations
wrangler.jsoncLocal and production D1 bindings

D1 provides the database binding; this project does not use a DATABASE_URL connection string. See the D1 migration documentation when planning a production schema change.

On this page