Skip to content

prometheus1704/Project-Management-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm i express cors dotenv helmet morgan body-parser

// For Prisma client npm i @prisma/client

npm i -D typescript ts-node-dev @types/node @types/express @types/cors @types/helmet prisma

npx tsc --init npx prisma init

<-------------- PRISMA COMMANDS ---------------->

1. Setup & Schema

  • npx prisma init
    Creates a new prisma/ folder with schema.prisma and .env.

  • npx prisma generate
    Generates the Prisma Client (@prisma/client) based on your schema.
    Run this after schema changes (auto-run on migrate dev).


2. Migrations (Safe Schema Changes with History)

  • npx prisma migrate dev --name <migration_name>
    Creates a migration file, applies it to the DB, regenerates Prisma Client.

  • npx prisma migrate deploy
    Applies all pending migrations to the DB. Use in production/staging.

  • npx prisma migrate reset
    Drops the DB, reapplies all migrations, runs seed script (if defined). ⚠️ Dev only.

  • npx prisma migrate status
    Shows which migrations are applied, pending, or failed.

  • npx prisma migrate dev --create-only --name <migration_name>
    Creates migration SQL without applying it (for manual edits).


3. DB Push / Pull (Direct Sync, No History)

  • npx prisma db push
    Pushes the schema directly to the DB (no migrations). Best for prototyping.

  • npx prisma db pull
    Introspects an existing DB → updates schema.prisma with models.


4. Database Tools

  • npx prisma studio
    Opens Prisma Studio (GUI to view & edit data).

  • npx prisma validate
    Validates schema.prisma.

  • npx prisma format
    Auto-formats schema.prisma.


5. Seeding

  • npx prisma db seed
    Runs your seed script to insert initial/test data.

⚡ Typical Workflow

  1. Initialize Prisma
    npx prisma init
    
    

Define models in schema.prisma.

Create & apply migrations

  • npx prisma migrate dev --name add_user_table

Use Prisma Client in code

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

Deploy to production

  • npx prisma migrate deploy

Debug/inspect data

  • npx prisma studio

<-------------- PRISMA NESTED QUERY ---------------->

for one to many relation give plural name and one to one give singular name for table

below in the include statement of the parent table/ main table

tablename:true

for all fields to inlcude

role:{ include:{ roleActions:true } }

for specific fields (nested query)

role:{ select:{ name:true roleActions:{ select:{ action:true } } } }

About

It is a automation in the project management.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published