Skip to content

Database

Quick reference for importing / exporting Postgres data and managing Payload migrations.

Import database

  • Restore the latest production dump from ./data into your local POSTGRES_URL:
bash
pnpm db:restore:latest
  • Optional format flags: --sql or --binary.
  • The restore script resets the public schema first (DROP SCHEMA ... CASCADE), so this is destructive for the target DB.

Export database

This can only be done if you have admin credentials. Ask Gijs/Camil. Export source/production DB (from SOURCE_POSTGRES_*) to ./data:

bash
pnpm db:dump:production
  • Optional flags (both scripts):
    • --sql / --binary
    • --repo-safe / --no-repo-safe
    • --max-git-file-mb=95
    • --chunk-size-mb=95

Repo-safe mode compresses large dumps (.xz/.gz) and can split them into .part-* chunks so they can go into github.com (max 100MB).

Payload migrations

If you want changes to the production database you need to work with migrations. To create a migration start with the latest db + migrations then run pnpm payload:migrate:create. This file needs to be checked into git and part of your PR.

Common commands:

bash
pnpm payload:migrate
pnpm payload:migrate:status
pnpm payload:migrate:create
pnpm payload:migrate:down

Payload migrations docs: https://payloadcms.com/docs/database/migrations

Also available: payload:migrate:refresh, payload:migrate:reset, payload:migrate:fresh.

Quirks / gotchas

  • Locally you can make changes to the database and interact with console to create tables/columns. When you're done create a migration
  • Local dev commonly uses Drizzle push mode. Do not mix that local push workflow with running migrations against the same local DB.
  • Double check your migration against latest dump. So:
    • pnpm db:restore:latest
    • pnpm payload:migrate
    • pnpm payload:migrate:create -> should be empty
  • Create migrations after finishing a coherent schema change, then review generated files before committing.