dansalan-microservice-common
v0.0.8
Published
Common classes and interfaces
Readme
Organization Service Microservice
Installation
$ npm installDatabase
- Install MySQL DB
- Configure DB and add connection details in
['.env.dev.local', '.env.dev', '.env.prod']whichever comes first.
Sample .env content:
DATABASE_TYPE=mysql
DATABASE_HOST=localhost
DATABASE_PORT=3306
DATABASE_USERNAME=root
DATABASE_PASSWORD=root
DATABASE_SCHEMA=OrganizationsDB
DATABASE_ENTITY_PATH=dist/**/*.entity.js
DATABASE_SYNCHRONIZE=falseset DATABASE_SYNCHRONIZE to false because we use the migration instead
Create a database schema specified in your connection details above, for example:
create database OrganizationsDB;TypeORM Migration
Schema changes should be run in migration to ensure that the development database has the same schema as the test and production.
Execute the command below to create a new migration file. Just change <ClassName> with the migration name ie. AddCityToCountryTable.
npm run typeorm migration:create -- -n <ClassName> -d src/migrationsAlternately, you could generate a migration with the changes made in the entity folder:
npm run typeorm migration:generate -- -n <ClassName>Running the Migrations:
npm run buildnpm run start or start:dev
It should execute all migration scripts that are not yet executed.
Running the app
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prodTest
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:covDevelopment
Create new module for an entity, for example: Role
nest g module rolesCreate new controller for the Role
nest g controller rolesCreate new service for the Role
nest g service roles