# Prisma Commands
## Here is a list of the commonly used Prisma commands and what they do:
### 1. `prisma init`
Initializes Prisma in your project by creating a `prisma` folder with a `schema.prisma` file and a `.env` file.
**Example:**
```bash
npx prisma init
Generates the Prisma Client based on your Prisma schema. Run this after modifying your schema.prisma
.
Example:
npx prisma generate
Pushes the schema changes in your schema.prisma
to your database without creating a migration. It synchronizes the Prisma schema with the database schema.
Example:
npx prisma db push
Creates a new migration based on the changes in your Prisma schema and applies it to your development database.
Example:
npx prisma migrate dev --name <migration_name>
Applies all pending migrations to your production database. Use this when deploying to production.
Example:
npx prisma migrate deploy
Marks a specific migration as applied or rolled back without running it. This can be useful in scenarios where a migration was manually applied or reverted.
Example:
npx prisma migrate resolve --applied <migration_id>
Resets the database by dropping all data and applying all migrations from scratch. Useful during development to start with a clean database.
Example:
npx prisma migrate reset
Runs the seed script defined in your prisma/schema.prisma
. This command helps seed your database with initial data.
Example:
npx prisma db seed
Introspects your database schema and updates the Prisma schema file (schema.prisma
) to reflect any changes in your database.
Example:
npx prisma db pull
Launches Prisma Studio, a web interface for browsing and editing your database data.
Example:
npx prisma studio
Formats the Prisma schema file to a standardized format.
Example:
npx prisma format
Outputs the current version of Prisma that you have installed.
Example:
npx prisma version
Validates the Prisma schema for any errors without applying any changes.
Example:
npx prisma validate
Compares two database states or schema files and outputs a list of differences.
Example:
npx prisma migrate diff --from-url <DATABASE_URL_1> --to-url <DATABASE_URL_2>
To enable replication, modify the replication settings in your MongoDB configuration file (mongod.conf
or equivalent).
Add the following lines:
replication:
replSetName: "myReplicaSet"
After making the changes, restart your MongoDB instance for the new replication settings to take effect.
Open your Mongo shell.
Switch to your desired database (for example, from test
to prisma
):
test> use prisma
switched to db prisma
Initiate the replica set by running the following command & make sure follow indentation:
prisma> rs.initiate({
_id: "myReplicaSet",
members: [{ _id: 0, host: "127.0.0.1:27017" }]
})
Check that the replica set has been initiated correctly. You should see:
{ ok: 1 }
For more information, visit the Prisma Documentation.