A Prisma-based schema generator CLI (generate/destroy models, fields, migrations)
npm install prismo-cli
_/_/_/ _/_/_/ _/_/_/ _/_/_/ _/ _/ _/_/
_/ _/ _/ _/ _/ _/ _/_/ _/_/ _/ _/
_/_/_/ _/_/_/ _/ _/_/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/_/_/ _/_/_/ _/ _/ _/_/
A Prisma-powered schema generator CLI
Generate models, fields, migrations just like Rails ā but for Prisma šÆ
---
ā Generate & destroy models
ā Add & remove fields with relation auto-handling
ā Supported relations:
ā” 1to1, 1toM, Mto1, MtoM
ā Cascade delete support (--cascade)
ā Migration automation (--migrate)
ā DB drop/reset with safety confirmation š
ā Intelligent CLI suggestions for typos
ā Fully styled --help menu šØ
ā Zero manual schema editing! š
---
``sh`
npm install -g prismo-cli`Verify installation:
`
prismo --help`bash
$ prismo --help
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Prismo CLI Help
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Usage:
prismo
Commands:
Generate
prismo g model
prismo g field
prismo g relation
Destroy
prismo d model
prismo d field
Database
prismo db:migrate
prismo db:reset Reset DB & reapply migrations
prismo db:drop Drop database
prismo db:seed Run Prisma seed script
prismo list models List all models in schema
prismo studio Launch Prisma Studio UI
Options:
-h, --help Show help
-v, --version Show version
-m , --migrate Automatically run migration
--cascade Enable cascade delete
Relation Types:
1to1, 1toM, Mto1, MtoM Specify relation type
Examples:
prismo g model User name:string email:string
prismo g field Post title:string
prismo d model Order
prismo db:migrate "add_users_table"
prismo studio
``š§± Usage Examples
Generate a model
sh`
prismo g model User name:string age:int -m`$3
`
š Creating Model
ā Schema formatted
ā Model "User" created successfully!
ā Run migration: prismo db:migrate "add_User"`prisma`
model User {
id Int @id @default(autoincrement())
name String
age Int
}`Add a field
sh
prismo g field User bio:string --migrate
``$3
š Adding Field`
ā Schema formatted
ā Fields added to User
ā Run: prismo db:migrate "update_User"`prisma`
model User {
id Int @id @default(autoincrement())
name String
age Int
bio String?}`Destroy a model safely
`
prismo d model Post`$3
`
ā Model "Post" removed successfully!
ā Run migration: prismo db:migrate "remove_post"`$3
`
ā Cannot destroy model "Post" š«
ā¹ Other models reference it:
ā - Comment
ā Destroy those models first.`List all models
`
prismo list models`$3
š Database Models
ā š¦ Model: Post
ā¹ - id String @id @default(uuid())
ā¹ - title String
ā¹ - age Int
ā¹ - createdAt DateTime @default(now())
ā All models listed.
`prismo db:migrate DB Commands
| Command | Description |
| ------------------- | ------------------------- |
| | Apply migrations |prismo db:drop
| | Drop DB instantly + delete migrations files as well (Use Carefully) |prismo db:reset
| | Drop + reapply migrations |
prismo g model User name:string age:int gender:string --migrate
prismo g model Profile title:string --migrate
`
`sh
# One User has One Profile
prismo g relation 1to1 User Profile --migrate
`
`js
model User {
id String @id @default(uuid())
name String
age Int
gender String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
profile Profile?
}
model Profile {
id String @id @default(uuid())
title String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id])
userId String @unique
}
`
2. 1toM Relation
Create the following models
`
prismo g model User name:string age:int --migrate
prismo g model Post title:string content:string --migrate
`
`sh
# One User can have Many Posts
prismo g relation 1toM User Post --migrate --cascade
`
`js
model User {
id String @id @default(uuid())
name String
age Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
posts Post[]
} model Post {
id String @id @default(uuid())
title String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
}
`
3. Mto1 Relation
Create the following models
`
prismo g model Category name:string --migrate
prismo g model Product name:string --migrate
`
`bash
# Many Products belong to One Category
prismo g relation Mto1 Product Category --migrate
`
`js
model Category {
id String @id @default(uuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt products Product[]
}
model Product {
id String @id @default(uuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
category Category @relation(fields: [categoryId], references: [id])
categoryId String
}
`
4. MtoM Relation
Create the following models
`
prismo g model Author name:string --migrate
prismo g model Book title:string --migrate
`
`bash
# Many Authors can write Many Books
prismo g relation MtoM Author Book --migrate
`
`js
model Author {
id String @id @default(uuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
books Book[] @relation("AuthorBooks")
}
model Book {
id String @id @default(uuid())
title String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
authors Author[] @relation("AuthorBooks")
}
`
š§āš» Contributing
1. Fork the project
2. Create a feature branch
3. Submit a PR
Before submitting, run:
`sh
to link your local changes for testing.
npm link
`
`bash
test commads locally
prismo list models
`š§© Issue Templates
Bug report template:
`
Command executed:
prismo [...]Expected behavior:
Actual behavior:
Prisma schema preview:
``Made with ā¤ļø by Manoj Sharma
Follow the project ā and contribute!