README.md
May 23, 2024 ยท View on GitHub
Description
The app use Nest Framework and PostgreSQL connection.
1. Preparation
-
Install Nodejs, Yarn, PostgreSQL, Docker
-
copy .env.example to .env
-
set up your database connection in .env
2. Install Dependencies
Install the dependencies for the Nest application:
# yarn
yarn install
3. Set Database schemas
# yarn
yarn migrate
4. Start NestJS Server
Run Nest Server in Development mode:
yarn start
# watch mode
yarn start:dev
Run Nest Server in Production mode:
yarn start:prod
GraphQL Playground for the NestJS Server is available here: http://localhost:4000/graphql
GraphQL Playground
You could use following example queries in the GraphQL Playground.
Some queries and mutations are secured by an auth guard. You have to acquire a JWT token from signup or login.
mutation {login(data: {username: "YOURUSER", password: "YOURPASSWORD"}) {refreshToken, accessToken, user {id} }}
Add the accessTokenas followed to HTTP HEADERS in the playground and replace YOURTOKEN like this:
{
"Authorization": "Bearer YOURTOKEN"
}
########################################
5*. Prisma Migrate
Prisma Migrate is used to manage the schema and migration of the database. Prisma datasource requires an environment variable DATABASE_URL for the connection to the PostgreSQL database. Prisma reads the DATABASE_URL from the root .env file.
Use Prisma Migrate in your development environment to
- Creates
migration.sqlfile - Updates Database Schema
- Generates Prisma Client
Note: Every time you update schema.prisma re-generate Prisma Client JS
yarn prisma:generate
# or
npx prisma generate
yarn migrate:dev
# or
npx prisma migrate dev
If you like to customize your migration.sql file run the following command. After making your customizations run npx prisma migrate dev to apply it.
yarn migrate:dev:create
# or
npx prisma migrate dev --create-only
If you are happy with your database changes you want to deploy those changes to your production database. Use prisma migrate deploy to apply all pending migrations, can also be used in CI/CD pipelines as it works without prompts.
yarn migrate:deploy
# or
npx prisma migrate deploy
6*. Seed the database data with this script
Execute the script with this command:
yarn seed
7. Test
# unit tests
$ yarn test
# e2e tests
$ yarn test:e2e
# test coverage
$ yarn test:cov