# Postgresql service ## Installation ```bash # install node modules $ npm install ``` ## Environment variables In order to run the code, some environment variables are needed. They are specified in the `template.env` file at the root of the project. For a local deployment: 1. `cp template.env .env` 2. Edit .env according to the chosen configuration The values will be read from the file by default, but you can override any of those by exporting manually the variable before launching the service. ## Running the app without docker You will need to provide a healthy connection to a database in order for the service to start. ```bash # development $ npm run start # watch mode $ npm run start:dev # production mode $ npm run start:prod ``` ## Running the app with docker ```bash # build $ docker-compose build # deploy $ docker-compose up [-d] # build and deploy $ docker-compose up --build [-d] ``` ## Migrations Migrations are done automaticaly the docker image on startup. You can run it manualy: MIGRATING=1 npm run migrate:run *ATTENTION* when migrating, tables belong to postgres, not to "user", you need to grant "user" the access to the tables. docker-compose exec database-postgres psql --user postgres --password services # Give the "POSTGRES_ADMIN_PASSWORD" password GRANT ALL ON ALL TABLES IN SCHEMA public TO "user"; Replace "user" by the database user given in .env file. ## Test Be carefull, end to end tests drop all data from you tables : ```bash # create a venv python3 -m venv venv . bin/activate # Install dependencies pip install -r tests/requirements.txt # Run end to end tests pytest ``` #FIXME: running tests destroys migration table, you can't apply migrations after this ## Setup Start the DATABASE, and use psql to setup database user "user" (or whatever name you gave it) rights : psql --user postgres services # giv postgres password GRANT ALL ON DATABASE services TO "user"; GRANT ALL ON ALL TABLES IN SCHEMA public TO "user"; GRANT ALL ON ALL SEQUENCES IN SCHEMA "public" TO "user";