Skip to content

Latest commit

 

History

History
81 lines (44 loc) · 2.8 KB

README.md

File metadata and controls

81 lines (44 loc) · 2.8 KB

Server

Back to root README.


Index


API File Structure Generation

When adding a new model to the schema.prisma, you might find yourself being annoyed at all the steps you have to go through to add the model resolvers to the /packages/server/src/api folder. To alleviate the great stress that comes with repetitive tasks like this one, theres now a new solution: yarn model:add 🎉

With yarn model:add 🎉 you can:

  • generate files and folders with the name of the model automatically
  • not be stressed

How to use it?

Simply type yarn model:add into your favorite terminal or terminal emulator and enter the name of the model you want to add to the api. With the power of god and anime, yarn model:add 🎉 will add folders and files with the name of the model.

Not satisfied with the results?

Sucks to be you! If you want to change the name of the files that get generated by yarn model:add 🎉 or their content, you can change the templates in the scripts/templates folder. A * in the file name will be replaced by the name of the model. To change the content of the templates, %Object and %object will be replaced by the title case and lower case model name respectively.


Database

Etournity is using a PostgreSQL database with Prisma as our ORM. This stack allows for typesafe data handling as well as ease of use.

Contents

  • Prisma ORM
  • ER-Model
  • Environments

Prisma ORM

An open source ORM created for TypeScript.

Prisma Schema

This is Prisma's way to define data models. It allows us to define models as easily readable objects and translates those to raw SQL behind the scenes. Read up on the specifics here.

Our Schema as well as migrations are located in /packages/server/prisma/.

Migrations

After changing the schema, create a migration using yarn migrate:save.

The changes are automatically applied on server start. To do this manually use yarn migrate:up.

Note: Conventionally, we try to stick to 1 migration per branch. You can easily delete all migrations you made in a branch and do one last migration before merging.

Local Setup

Our local setup is using Docker.

In order to access the local DB in your Database Tool use the URL from our /server/.env.example file.

Commands

To start a database instance use yarn db:bg.

Note: The container keeps running until you restart your system.

We have set up automatic seeding for testing, which can be reset through yarn db:reset.

To stop the container use yarn db:stop-bg.

To delete the container use yarn db:down.