Node.js, Prisma & PostgreSQL

Lesson 4 of 12

Migrations with Prisma Migrate

A migration is a versioned, applied change to your database schema. Prisma Migrate generates and runs the SQL for you, based on the differences it sees in schema.prisma.

npx prisma migrate dev --name init

This command:

  1. Compares your schema to the database's current state.
  2. Generates a plain SQL migration file (you can open and read it, it's just CREATE TABLE, ALTER TABLE, and so on).
  3. Applies it to your database.
  4. Regenerates Prisma Client so your code's types match the new schema.

Each migration lives in prisma/migrations/<timestamp>_init/migration.sql, committed to version control alongside your code, exactly like the rest of your app's history.

Inspecting your data

npx prisma studio

Opens a local, visual browser for your database, handy for checking that a migration or query did what you expected.

📝 Migrations Quiz

Passing score: 70%
  1. 1.What does npx prisma migrate dev generate?

  2. 2.npx prisma ____ opens a local, visual browser for your database.

  3. 3.Prisma migration files are meant to be committed to version control.