Skip to content

Developer Commands: Database

Miró Sorja edited this page Jun 6, 2024 · 1 revision

Developer Commands: Database

We develop against production copy of the database.
These commands expect you to have docker setup as explained in README.md#create-your-own-local-datbase

Copying a database dump to container

Database container expected to be located at ~/downloads/backup
When downloading the backup, the default name is {uuid}.
You can rename to backup with mv {uuid} backup

docker cp ~/downloads/backup fra-db:/

Restoring (production) copy

To restore a copy from backup, the backup is expected to be located in root of the container (/)

dropdb frap-dev --user frap
createdb --owner=frap --username=frap frap-dev 
pg_restore --no-owner --clean --if-exists --verbose -U frap -d frap-dev /backup'

Creating and using snapshot to quickly reset DB

Many times when running migrations, you might want to roll back to initial state (eg. prod)
To avoid using the slow pg_restore you can use snapshots.

To create a snapshot:

docker exec -it fra-db bash
createdb -U frap -T frap-dev snapshot

This creates a snapshot called snapshot from the current state of DB frap-dev

To restore the snapshot, simply drop the db and switch the params:

docker exec -it fra-db bash
dropdb frap-dev -U frap
time createdb -U frap -T snapshot frap-dev