Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prisma Demo

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.

Prerequisites

  • 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

Getting up and running

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:18

Next, copy the .env.sample file to .env:

cp .env.sample .env

Then, install the dependencies:

npm install

After, run the DB migrations for the first time:

npx prisma migrate dev

Now, you can generate your Prisma types:

npx prisma generate

Finally, run the attached seed.ts script to make sure everything is working fine:

npx tsx seed.ts

Commands you might find useful

Create a migration and update the database schema:

npx prisma migrate dev --name your_migration_name

Open the Prisma Studio to visually browse and manage your database:

npx prisma studio

Made a mistake in one of your migrations? No problem, delete the migration folder and reset the database with:

npx prisma migrate reset

How to submit your work

  1. Fork this repo to your own GitHub account.
  2. Make your changes there.
  3. Open a Pull Request against this repo.

What you need to do

  1. Add a Publisher model, a many-to-one relationship between Publisher and Book.
  2. Add a Genre model, a many-to-many relationship between Genre and Book.
  3. 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.

A note on using AI agents

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages