Skip to content

DarkLite1/backend

Repository files navigation

Backend

This is a backend server that can be used with Graphql queries and mutations to consume the exposed services (API's, databases, ...). It is intended to be the single backend gateway that can be used with multiple frontends.

Setup

Install the dependencies

yarn

Different modes

Start the app in development mode

Connect to the test database and run the graphql server in development mode.

yarn dev

Start the app for production

Start the application in production mode. This will read the environment variables and use them to start up the graphql server on the correct port and opens the connections to the production databases.

yarn start

Running tests

Run the test suite

Run end-to-end tests against the graphql endpoints, aka resolvers. These tests will use the test database and directly consume the Graphql schema without the need to start a test server.

yarn test // run all tests
yarn test "src\\resolvers\\PreferenceResolver.test.ts" // specific file to test

Developing

Every commit to the GitHub master branch will trigger a new build on the OpenShift platform so the changes made will be in production when the OpenShift build finishes.

Working with git

Commit changes to a single file, push them and have them deployed on OpenShift:

git commit -m 'updated readme' .\README.md
git push

Handle database changes

When working in development mode with yarn dev changes to the database structure might be required. Every change to the database schema within the code needs to be applied to the database as well.

As a first step, changes are applied to the test database only (step 1 & 2). When they seem to be correct they can then be applied to the production database (step 3).

It is best practice to run the procedure below for every single change to the database (i.e. rename a column, add a table, ...). This will create a migration file for each change and allows an easy rollback process. Do not delete the migration files afterwards as they can be used to rebuild a complete database when needed.

Update the databases

  1. Generate a migration file with the name of the change

    yarn typeorm-migration-generate -- --n="removeColumnTitle"
  2. Apply the changes to the test database

    yarn typeorm-migration-run
  3. Apply the changes to the production database

    yarn typeorm-migration-run-prod

Other database actions

  • Revert the last executed migration:
yarn typeorm-migration-revert
  • Show all migrations and whether they have been run or not
yarn typeorm-migration-show

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published