Migrations
The SQL schema

Migrations

A migration is a change to the database's shape, written as a file so that it can be applied the same way everywhere: on a developer's machine, in testing, in staging and in production. When the schema changes, a migration carries that change to each database.

Description

The Drizzle configuration says where the schema and the migrations live. Running pnpm db:generate compares the schema to the last migration and writes the next numbered SQL file. Anything Drizzle cannot express, such as a trigger, a policy, a grant or a move of data, is written by hand and appended to that same file. Running pnpm db:migrate applies the migrations locally. Running pnpm db:deploy runs the deploy migration, which is the command Railway runs before each deploy. Running pnpm db:snapshot writes the whole schema to a SQL snapshot, with a JSON snapshot beside it.

On a developer's machine the database is named adh_<branch>, after the branch being worked on, in the adh-local-pg container on port 5433. The connection is made as the app role, so row-level security is in force in development just as it is in production.

Tech Detail
Hosting
Railway
Tooling
pnpm