App architeture: link to whimsical
- Docker
- MySQL 8
- Prisma/Client to generate models
- Vs Code to run with devcontainer
-
Use the nx generator and give the name as : models-
-
After that, create a folder called schema under src
-
Add 3 scripts inside package.json to:
- Will update the prisma.schema with the database schema.
<database-name>
-update: npx prisma db pull --schema=./libs/models/<database-name>
/src/schema/schema.prisma
- Will generate the prisma cliente.
<database-name>
-generate: prisma generate --schema=./libs/models/<database-name>
/src/schema/schema.prisma
- Will create the migration
<database-name>
-migrate: prisma migrate dev --create-only --schema=./libs/models/<database-name>
/src/schema/schema.prisma
- Will run the prisma studio
<database-name>
-studio: prisma studio --create-only --schema=./libs/models/<database-name>
/src/schema/schema.prisma
- Will update the prisma.schema with the database schema.
-
Then create a nest module, which includes the connection service and will be used on the API'S and provides the connection
-
To avoid lint errors, exclude the prisma client from eslint
"ignorePatterns": ["!**/*", "**/prisma"],
-
Add an asset inside workspace.json for each project that used a prisma service
- E.g.:
"options": { "outputPath": "dist/apps/atlas", "main": "apps/atlas/src/main.ts", "tsConfig": "apps/atlas/tsconfig.app.json", "assets": [ "apps/atlas/src/assets", { "glob": "schema.prisma", "input": "libs/models/veritas/src/schema", "output": "." } ] },
- E.g.:
-
Add an asset inside workspace.json for each project that used a prisma service
- E.g.:
"options": { "outputPath": "dist/apps/atlas", "main": "apps/atlas/src/main.ts", "tsConfig": "apps/atlas/tsconfig.app.json", "assets": [ "apps/atlas/src/assets", { "glob": "schema.prisma", "input": "libs/models/veritas/src/schema", "output": "." } ] },
- E.g.:
There is a generator called nest-module
. To use do:
nx workspace-generator nest-module --app <name of the project>
The command will generate the follow directory:
- /name
- /providers
- name.service.ts
- /controllers
- name.controller.ts
- name.module.ts
- /providers
I got permission issues with docker while trying to run scripts or packages commands I could solve by the following:
- sudo chown -R $USER /workspace
- sudo chown -R $USER /root/.cache