top 10 prisma commands
Prisma is a powerful ORM for Node.js and TypeScript, allowing developers to work with databases in a type-safe manner. Here are the top 10 Prisma commands that are commonly used:
1. Initialize a Prisma Project
npx prisma init
This command initializes a new Prisma project by creating a prisma
directory with a schema.prisma
file.
2. Generate Prisma Client
npx prisma generate
Generates the Prisma Client, which is used to interact with your database. Run this command after making changes to your schema.prisma
file.
3. Migrate Your Database
npx prisma migrate dev --name <migration_name>
Creates a new migration and applies it to the database. The --name
flag specifies the name of the migration.
4. Apply Migrations
npx prisma migrate deploy
Applies all pending migrations to the database.
5. Introspect Your Database
npx prisma db pull
Introspects your existing database and updates your schema.prisma
file to reflect the current state of the database schema.
6. Push Schema to Database
npx prisma db push
Pushes the state of your schema.prisma
file to the database without generating a migration.
7. Seed Your Database
npx prisma db seed
Runs the seed script specified in your prisma
directory to populate your database with initial data.
8. Reset Your Database
npx prisma migrate reset
Resets the database by rolling back all migrations, then re-applies them from scratch. This command is useful during development.
9. Check Migration Status
npx prisma migrate status
Shows the current status of your migrations, including which migrations have been applied and which are pending.
10. Studio (Web UI)
npx prisma studio
Launches Prisma Studio, a web-based UI to explore and manipulate the data in your database.
Bonus Commands
Format Schema
npx prisma format
Formats your schema.prisma
file according to Prisma's style guide.
Validate Schema
npx prisma validate
Validates your schema.prisma
file for correctness.
These commands cover the essential operations for managing and interacting with databases using Prisma.