This project uses pnpm to manage dependencies. Install pnpm with npm install -g pnpm
and run pnpm install
to install dependencies.
see https://pnpm.io/installation for more information on pnpm.
This project uses volta to manage node versions. Install volta and run volta install
to install the correct node version.
To install volta run the following command in the terminal.
curl https://get.volta.sh | bash
- install the project dependencies
pnpm install
- create a
.env
file with the contents of.env.example
knex migrate:latest
knex seed:run
npm run dev
- test the api endpoints work with VSCode REST Client
imports a db from local backup.sql
file
npm run db:drop
npm run db:create
npm run db:import
alternatively you can copy the db to the container with npm run db:copy
and from the shell you can import the db with:
psql -U postgres -d <dbname> < backup.sql
If you encounter
ERROR: invalid byte sequence for encoding "UTF8": 0xff
Simply create a new backup.sql file and copy the contents of the old file into a new file. Then run the import scripts.
also check the collation of your db if you encounter issues
echo $LANG
`en_US.utf8` or `en_GB.UTF-8`
export LANG=en_GB.UTF-8
to backup the db simply run npm run db:backup
this will run the following command on the docker container
docker exec <db-container-name> /usr/bin/pg_dump -U <dbuser> <dbname> > backup.sql
you will need to create new tables with a migration or with a custom script
to use migrations install knex globally npm install -g knex
- https://www.jsparling.com/set-up-bookshelf-js-for-node-js/
- https://knexjs.org/guide/schema-builder.html#datetime
You can create and run migrations with the knex cli.
- create a migration
knex migrate:make create_table
- add logic to the migration file to create required tables
- run the migration
knex migrate:latest
to update the db with new tables
you can see the database with data; the migrations will only create the required tables
To run a seed use npm run seed:run
to run the seed file