Provides a service layer to read, create and delete reports from a SQL table.
Reading: The main application will make a request to this api. This service will then connect to the database, get the data back and send it to the main application if it is successful
Saving: The main application will send the data to this service as an end point. This service will connect to a database and store that data and respond back to the main application if successful
This repo uses knex which, if NODE_ENV is not set, will try to connect to a localhost instance of postgres. If it is set, it will try to use the below environmental variables DB_HOST
etc... to connect to a formal DB using the proper credentials.
You can set the following to specific how you want your results to look:
MAX_PAYLOAD_SIZE
- Max payload size for request bodies. Increase this is request body sizes contain base64 strings for storing thumbnail images into the save & return 'session' dataPORT
- Custom port you can run this service onMAX_DATA_AGE
- Max age in days of data before it is cleaned from the RDS instanceSERVICE_NAME
- This specifies which HOF service to use migrations, seeds and db config from in the './services' folderLATEST_MIGRATION
- This is the latest migration you wanted automated migrations to run up to based on the migration names in the relevant service folder under './services'CLIENT
- This is the database client type. This defaults to postgresql.DB_HOST
,DB_USER
,DB_PASS
,DB_NAME
- These are production credentials for accessing the relevant database.
The migrations and seeds folders are used by knex to setup a local DB with dummy information for testing the service. These are not used in production where it is assumed a separate DB is setup for knex to connect to that is already setup.
Run the following commands to setup a test DB:
brew install postgres
brew services start postgresql
psql postgres
CREATE ROLE postgres WITH LOGIN PASSWORD 'postgres';
ALTER ROLE postgres WITH SUPERUSER;
CREATE ROLE knex WITH LOGIN PASSWORD 'knex';
ALTER ROLE knex WITH SUPERUSER;
CREATE DATABASE <DB_NAME>;
\q
If you download Postico for Mac (https://eggerapps.at/postico/), you can then inspect your postgres DB for example and look at the test entries inserted into the test table 'Reports'.
You then need to use a knexfile with migrations and seeds folders to populate your database. The ms-schema repo which is used for migrations in the Modern Slavery service (https://github.com/UKHomeOffice/ms-schema) can be used as a test example and is included in this project. You can run
yarn run db:local:setup
from that repo to setup your database.
Setup a '.env' file for the service you want to test this against. For example:
SERVICE_NAME=asc
NODE_ENV=local
LATEST_MIGRATION=20230428215725_saved_applications (optional - otherwise runs all migrations)
Then run yarn run db:local:migrate
to update your local database with the relevant migrations for local testing.
The application can be run on your local machine
To create a new migration, go into the relevant service folder, i.e. cd ./services/<service_name>
, ensure you have npm i knex -g
and run:
SERVICE_NAME=<service_name>
knex migrate:make <migration_name>
This will then create the new migration in the migrations folder of the service Then run
NODE_ENV=local
yarn db:local:migrate
You will need to have the following installed:
Node JS ( LTS Hydrogen v18.x )
NPM ( v8.x )
Yarn (v1.x)
PostgreSQL ( v12.x )
Ensure your database service is available and running.
Then to run the service use:
npm start
to run the server.
With the server running you can run the main app with save and return lookup UI functionality. See details of how to do this in modern slavery application