This project is for trying out the Prisma ORM with a PostgreSQL database.
Please note this was created on a windows PC, while running on WSL2. Keep that in mind if you run into any issues.
- Docker - for running a local PostgreSQL database
- NodeJS
- This repo was built using NodeJS v24+ (specifically v24.11.1)
- Either install NodeJS if you don't have it already or switch to any v24+ version using any tool version management utility like
nvm,mise,asdf...
- Optional: A DB GUI tool like pgAdmin or DBeaver, as it will help browse your database visually - or you can also use the Prisma Studio
First, start a local PostgreSQL database using Docker:
docker run --name prisma-demo-postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=appdb \
-p 5432:5432 \
-d postgres:18Next, copy the .env.sample file to .env:
cp .env.sample .envThen, install the dependencies:
npm installAfter, run the DB migrations for the first time:
npx prisma migrate devNow, you can generate your Prisma types:
npx prisma generateFinally, run the attached seed.ts script to make sure everything is working fine:
npx tsx seed.tsCreate a migration and update the database schema:
npx prisma migrate dev --name your_migration_nameOpen the Prisma Studio to visually browse and manage your database:
npx prisma studioMade a mistake in one of your migrations? No problem, delete the migration folder and reset the database with:
npx prisma migrate reset- Fork this repo to your own GitHub account.
- Make your changes there.
- Open a Pull Request against this repo.
- Add a Publisher model, a many-to-one relationship between Publisher and Book.
- Add a Genre model, a many-to-many relationship between Genre and Book.
- Add timestamps (createdAt, updatedAt) to all models.
Bonus Points: Create a review system where users can leave reviews for books, including a rating and comment.
Extra Bonus Points Create a DB VIEW for popular books books with an average rating above 4. Hint: you can make use of npx prisma migrate dev --create-only
NOTE: Make sure to add seeding using faker.js for any new models you create.
This exercise is meant to deepen your understanding of Prisma, schema design, and migrations. If you plan to use an AI agent, don't ask it to generate the full solution. Instead, guide it with something like:
Act as a mentor. Do not give me the full solution.
Help me step by step with hints, explanations, and guiding questions so I can implement:
- The Publisher model and its relationship to Book
- The Genre many-to-many relationship
- Timestamps on all models
- (Bonus) A review system and a DB VIEW for popular books
Focus on helping me understand, not completing the task for me.
The goal is to understand what you're doing, not just finish the assignment.