TEA PlatformTEA Docs
Technical DocumentationDeployment

Database management

Back up, restore and migrate the PostgreSQL database used by a TEA Platform deployment.

Edit on GitHub

The application uses PostgreSQL through the Prisma client in lib/prisma.ts. The production compose file names its database container tea_postgres, its default database tea, and its default database user tea_user. Replace those defaults in the examples if your deployment uses different values.

A restore or reset can remove current data. Take a backup, verify that it can be read, and rehearse the procedure against a separate database before touching a production deployment.

Back up the database

For the default production compose values, pg_dump can make a SQL backup from the database container:

docker exec tea_postgres pg_dump -U tea_user tea > tea-backup.sql

Store the backup outside the host and apply an appropriate retention policy. The repository does not schedule database backups for a self-hosted compose installation. The application's Google Drive backup feature exports assurance cases; it is not a replacement for a database backup of users, grants and other records.

Restore a backup

Stop application writes before restoring, and restore into a prepared empty database. For a plain SQL backup and the default compose values, the import command is:

docker exec -i tea_postgres psql -U tea_user tea < tea-backup.sql

Check the restored database and application before resuming writes. A plain SQL dump replayed over existing objects can fail or leave a mixed state, so do not treat the command above as an in-place rollback. If the restore changes the schema version, bring the application and migration history into agreement before putting it back into service.

Apply schema changes

The repository keeps hand-written SQL migrations in prisma/migrations/. When changing the schema, update prisma/schema.prisma, write and review the SQL migration, and test it against a disposable database. The deployment operation is prisma migrate deploy; do not use prisma migrate dev to generate a migration for this repository.

The production image's scripts/docker-entrypoint.sh runs prisma migrate deploy before starting Next.js. The local compose application's command runs the same deployment step and then seeds development data. Normally you do not need a second manual migration command inside a running tea_app container. If a migration fails, investigate the database state and migration SQL before using a resolve operation. prisma migrate resolve changes migration tracking; it does not reverse the SQL effects of a migration.

Connections and checks

DATABASE_URL supplies the PostgreSQL connection string. lib/prisma.ts creates a pg pool for the Prisma adapter. DB_POOL_TIMEOUT_MS sets how long a request waits for a pool connection; the default is 5000 ms. Check the application logs for database errors and the deployment overview for the main configuration variables.

The local compose file also defines postgres-test on host port 5433. It uses disposable memory-backed storage and relaxed durability for integration tests. Do not use that service for development data or production records.

MIT 2026 © Alan Turing InstituteTrustworthy and Ethical Assurance Platform