Database actions
Accessing the database
For your database IDE, we recommend you use Beekeeper Studio (open-source edition).
Accessing the database locally
Ensure that Docker (at least the db container) is running. Then, use the local development settings:
- Host:
localhost - Port: 5432
- Username:
dev - Password:
dev - Default database:
dreambound
Running Knex commands (migrations)
Any Knex command you would ordinarily run as knex [command] can instead be run as
cd platform && npm run db -- [command]
Running all migrations not already run
cd platform && npm run db:migrate
Rolling back / down migrations
cd platform && npm run db -- migrate:rollback
Seed the database with test data
cd platform && npm run db:data:restore
Writing a new migration
To create a file for a new migration with name_of_migration prefixed by a timestamp:
cd platform && npm run db -- migrate:make [name_of_migration]
A loose naming convention for migrations is the table name followed by a short description of the change. For
example, table1_rename_col1_to_col2.
Wiping the database
To rollback all migrations and then run them again:
cd platform && npm run db:data:restore
Note that if your down migrations are broken/do not work, this command will fail. You would need to create a new database via Docker instead:
docker-compose down # Shut down Docker fully
docker volume rm dream_dream_db # Delete the database volume
docker-compose up # Start Docker again (this creates a new volume automatically)
pushd platform;
npm run db:migrate # Migrate the database
popd;