Prisma (migrations)
Schema definition
The schema is defined in core/prisma/schema/schema.prisma .
See the type documenation for defining more complex types.
Migrations
Creating new migrations
To modify the database schema, you need to create a migration.
- Run
pnpm migrate-dev - Enter the name of the migration (e.g.
add-new-field) - Say yes every time (this will create a new migration file in the
core/prisma/migrationsdirectory) - Modify the migration file to do things like data-migrations if necessary.
You can also create an empty migration, by running
pnpm -F core prisma migrate -- --create-onlywrite your migration, then
pnpm -F core migrate-devMigrations in production
Migrations are run before the container starts. This is currently (2025-06-05) defined here
History Tables
We have a number of tables that exist just to record the history of a table, along with the entity that made the change. They serve both as a way to audit changes and as a way to reconstruct the value of an entity (usually a Pub) at a point in time.
How to create one
- Run
pnpm db:generate-history-table - Enter the name of the original table (e.g.
pubs) - Say yes every time
- Run
pnpm db:migrate-dev(probably twice for good measure) - Tadah! You should have a new table called
pubs_history
This will also add a new column to the original table called lastModifiedBy of type LastModifiedBy. This will probably mean you need to update some application level code in order to actually use it.
The tables are stored in the core/prisma/schema/history-tables directory.