# Prisma ORM Explained: The Commands Every Developer Should Actually Know

The first time I used Prisma, I thought it was just another ORM.

A few weeks later, I realized Prisma is actually three things:

*   A database migration tool
    
*   A type-safe query builder
    
*   A schema management system
    

The confusion usually starts when developers see commands like:

```bash
prisma migrate dev
prisma generate
prisma migrate deploy
```

They sound similar, but they do very different things.

This guide is the Prisma cheat sheet I wish I had when starting out.

* * *

## What is Prisma?

**Prisma ORM** helps you interact with your database using a type-safe API instead of writing raw SQL everywhere. It also manages schema changes through migrations and generates TypeScript types directly from your schema. ([Prisma](https://www.prisma.io/?utm_source=chatgpt.com))

Think of it like:

> Database Schema → Prisma → Type-Safe API → Your Application

Instead of:

```sql
SELECT * FROM users;
```

You write:

```ts
const users = await prisma.user.findMany();
```

* * *

## Why Prisma Is So Popular

### 📝 Git-Friendly Migrations

Every schema change becomes a migration file that can be committed to Git.

```text
prisma/
└── migrations/
```

This means your database history lives alongside your code. ([Prisma](https://www.prisma.io/docs/orm/prisma-migrate?utm_source=chatgpt.com))

* * *

### 🚀 Type Safety

When you update your schema:

```prisma
model User {
  id    Int    @id
  email String
}
```

Prisma automatically updates your TypeScript types.

No more:

```ts
user.emial
```

bugs.

* * *

### 🔄 Easier Refactoring

Changing database columns, relationships, or tables becomes much safer because Prisma updates the generated client accordingly.

* * *

## Getting Started with Prisma

### Step 1: Install Prisma

```bash
npm install prisma --save-dev
npm install @prisma/client
```

Or globally:

```bash
npm install -g prisma
```

* * *

### Step 2: Initialize Prisma

```bash
npx prisma init --output ../generated/prisma
```

This creates:

```text
prisma/
├── schema.prisma
└── migrations/
```

* * *

### Existing Database?

Configure your database URL and pull your schema:

```bash
prisma db pull
```

Prisma will inspect your database and generate models automatically. ([Prisma](https://www.prisma.io/docs/orm/prisma-migrate/getting-started?utm_source=chatgpt.com))

* * *

## Create Your First Model

Inside:

`Schema.prisma`

```prisma
model Restaurant {
  id   Int    @id @default(autoincrement())
  name String
}
```

* * *

## Create Database Tables

Run:

```bash
npx prisma migrate dev --name init
```

Prisma will:

✅ Compare schemas

✅ Generate migration SQL files

✅ Apply migrations to your development database configured in .env

✅ Update migration history

✅ Create database tables

Prisma stores migration history in the `_prisma_migrations` table. ([Prisma](https://www.prisma.io/docs/cli/migrate/dev?utm_source=chatgpt.com))

* * *

## The Prisma Commands You Need to Know

### 1\. Prisma Studio

Launch Prisma's built-in database GUI:

```bash
npx prisma studio
```

Opens:

```text
http://localhost:5555
```

Think of it as a lightweight admin panel for your database.

You can:

*   View records
    
*   Edit data
    
*   Delete records
    
*   Inspect relationships
    

without writing SQL.

* * *

### 2\. prisma migrate dev

Probably the most important command:

```bash
npx prisma migrate dev --name add_users
```

What actually happens?

1.  Checks migration history
    
2.  Detects schema changes
    
3.  Creates a migration file
    
4.  Applies migration to your development database
    
5.  Updates `_prisma_migrations` history table
    

Prisma explicitly recommends using this command only during development. ([Prisma](https://www.prisma.io/docs/cli/migrate/dev?utm_source=chatgpt.com))

⚠️ **Never run this on production.**

* * *

### 3\. prisma generate

```bash
npx prisma generate
```

This regenerates the Prisma Client based on your schema.

Why does this matter?

Because your code uses generated APIs like:

```ts
prisma.user.findMany()
```

Whenever your schema changes, regenerate the client.

```bash
npx prisma generate
```

Prisma Client is generated from your schema and provides the type-safe API your application uses. ([Prisma](https://www.prisma.io/?utm_source=chatgpt.com))

* * *

### 4\. prisma migrate deploy

This is the production command.

```bash
npx prisma migrate deploy
```

Unlike `migrate dev`, it does **not**:

❌ Generate migrations

❌ Detect schema drift

❌ Create migration files

It simply:

✅ Looks for migration files already committed to Git

✅ Applies any pending migrations

That's exactly why it's safe for production environments. ([Prisma](https://www.prisma.io/docs/cli/migrate/deploy?utm_source=chatgpt.com))

A typical workflow:

```text
Development
      ↓
prisma migrate dev
      ↓
Git Commit
      ↓
Production
      ↓
prisma migrate deploy
```

* * *

### 5\. prisma migrate status

Check whether your database and migration files are in sync:

```bash
npx prisma migrate status
```

Useful before deployments.

* * *

### 6\. prisma migrate reset

Need a clean slate?

```bash
npx prisma migrate reset
```

This command:

*   Drops the database
    
*   Recreates it
    
*   Reapplies all migrations
    

⚠️ All data is lost.

Use only in development environments. ([Prisma](https://www.prisma.io/docs/cli/migrate/deploy?utm_source=chatgpt.com))

* * *

## Too Many Migration Files?

Every time you run:

```bash
npx prisma migrate dev --name something
```

a new migration gets created.

During MVP development, it's common to accumulate dozens of migrations & that's totally normal because that is how you see your schema history.

Example:

```text
migrations/
├── add_user
├── add_role
├── add_status
├── fix_role
├── fix_role_again
```

Many teams periodically clean this up.

Reset:

```bash
npx prisma migrate reset
```

Delete:

```text
prisma/migrations/
```

Create a fresh migration:

```bash
npx prisma migrate dev --name init
```

Result:

```text
migrations/
└── init
```

Much cleaner.

* * *

## My Recommended Prisma Workflow

### Development

```bash
# Modify schema.prisma

npx prisma migrate dev --name add_feature

npx prisma generate

npx prisma studio
```

### Production

```bash
# CI/CD

npx prisma migrate deploy
```

Never:

```bash
npx prisma migrate dev
```

on production servers. Prisma's documentation recommends using `migrate deploy` for production and CI/CD workflows. ([Prisma](https://www.prisma.io/docs/orm/prisma-client/deployment/deploy-database-changes-with-prisma-migrate?utm_source=chatgpt.com))

* * *

## Final Thoughts

Could you build your app using only PostgreSQL and raw SQL files?

Absolutely.

But once your project starts growing, Prisma gives you:

*   Type safety
    
*   Migration history
    
*   Better developer experience
    
*   Cleaner code
    
*   Easier schema management
    

For small prototypes, raw SQL is fine.

For real-world TypeScript applications, Prisma quickly pays for itself.

* * *

## Useful Resources

*   [Prisma Documentation](https://www.prisma.io/docs?utm_source=chatgpt.com)
    
*   [Prisma Migrate Guide](https://www.prisma.io/docs/orm/prisma-migrate?utm_source=chatgpt.com)
    
*   [Prisma CLI Reference](https://www.prisma.io/docs/orm/reference/prisma-cli-reference?utm_source=chatgpt.com)
    
*   [Prisma GitHub Repository](https://github.com/prisma/prisma?utm_source=chatgpt.com)
