This package contains all the entities and data access layer that can be used in the Backend or Lambda functions. We use Prisma as the ORM to create database migrations and entities.
- Node.js
- Typescript
- Prisma
Make sure you have this tools installed before running the project
- Node.js 18+
- Yarn
- PlanetScale CLI
Delete the existing folders output from build commands
yarn clean
Install node modules
yarn install
Create the .env file from the template
cp .env.template .env
# open .env file and update it with your local environment configuration
nano .env
This project uses PlanetScale for database and to connect to the database locally, you must authenticate first (Ask the credentials to @tericcabrel). Once authenticated from the terminal, execute the commands below on two separate terminals.
# On a terminal
yarn db:dev
# On a second terminal (only necessary if you update the prisma schema)
yarn db:shadow
The shadow database run on Docker, so don't forget to stop it when you don't need it
yarn db:shadow:stop
yarn db:generate
yarn db:migrate:dev
yarn db:seed
To generate a database migration, we run the command below:
yarn db:migrate:dev --name <migration-name>
Once done, make a copy of the file prisma/schema.prisma
to prisma/schema.test.prisma
.
Open the copied file and remove the line shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
.
This action is required to make the test executions easier in the package domain (packages/domain).
- Reset the database without seeding:
db:reset:dev
- Reset the database with seeding:
db:reset:dev:seed
- Open Prisma Studio to browse your DB:
db:view
- Lint the Prisma schema file:
db:format
To publish the database schema changes in production, you must create a deployment request. Run the command below to do that
yarn db:deploy:create
Build the package to generate types declaration required to provide autocompletion while using the functions in the core or Lambda functions
yarn build
A dist
folder will be generated.
Run the command below to run all the tests
yarn test
To run a specific test file, append the filename after the command
yarn test id.test.ts
ESLint and Prettier are used to normalize the code style across the project. Linting the code make sure there is no error
yarn lint