database-cli
Skill5 starsChanged 10 months agoMITView on GitHub
Database management with Prisma ORM. Use for migrations, schema management, seeding, and database queries.
- Installs packages
In this repository11 other files it gives its agents.
- agent-browserSkill
- apple-docsSkill
- changelog-generatorSkill
- code-reviewSkill
- docker-cliSkill
- github-actionsSkill
- git-workflowSkill
- lighthouse-auditSkill
- testingSkill
- vercel-cliSkill
- xcode-mcp-app-testingSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 132
After generating, restart your dev server or TypeScript server.
- Very specific: line 397
Run npx prisma migrate deploy in CI/CD
- Very specific: line 398
Don't use db push in production
- Distinctive: line 401
Use transactions for related operations
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
database-cli
Database management with Prisma ORM - migrations, schema management, seeding, and database operations.
Installation
npm install prisma --save-dev
npm install @prisma/client
npx prisma initQuick Reference
npx prisma generate # Generate Prisma Client
npx prisma db push # Push schema to DB (dev)
npx prisma migrate dev # Create and apply migration
npx prisma migrate deploy # Apply migrations (prod)
npx prisma studio # Open GUI browser
npx prisma db seed # Run seed script
npx prisma format # Format schema fileSchema Management
prisma/schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
email String @unique
name String?
password String
role Role @default(USER)
posts Post[]
profile Profile?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([email])
}
model Post {
id String @id @default(cuid())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
tags Tag[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([authorId])
}
model Profile {
id String @id @default(cuid())
bio String?
avatar String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @unique
}
model Tag {
id String @id @default(cuid())
name String @unique
posts Post[]
}
enum Role {
USER
ADMIN
}Migrations
Development
# Create migration from schema changes
npx prisma migrate dev --name init
npx prisma migrate dev --name add_user_role
# Apply without creating migration (prototyping)
npx prisma db push
# Reset database (drops all data!)
npx prisma migrate resetProduction
# Apply pending migrations
npx prisma migrate deploy
# Check migration status
npx prisma migrate statusMigration Commands
npx prisma migrate dev # Create & apply migration
npx prisma migrate deploy # Apply migrations (CI/CD)
npx prisma migrate reset # Reset database
npx prisma migrate status # Check status
npx prisma migrate resolve --applied "migration_name" # Mark as appliedGenerate Client
npx prisma generate # Generate after schema changeAfter generating, restart your dev server or TypeScript server.
Prisma Studio
npx prisma studio # Opens at localhost:5555
npx prisma studio --port 5556 # Custom portSeeding
package.json
{
"prisma": {
"seed": "tsx prisma/seed.ts"
}
}prisma/seed.ts
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
// Clean existing data
await prisma.post.deleteMany()
await prisma.user.deleteMany()
// Create users
const admin = await prisma.user.create({
data: {
email: 'admin@example.com',
name: 'Admin User',
password: 'hashed_password',
role: 'ADMIN',
profile: {
create: {
bio: 'System administrator',
},
},
},
})
const user = await prisma.user.create({
data: {
email: 'user@example.com',
name: 'Regular User',
password: 'hashed_password',
posts: {
create: [
{
title: 'First Post',
content: 'Hello World!',
published: true,
},
{
title: 'Draft Post',
content: 'Work in progress...',
published: false,
},
],
},
},
})
console.log({ admin, user })
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})Run Seed
npx prisma db seedCommon Queries
Create
// Single record
const user = await prisma.user.create({
data: {
email: 'test@example.com',
name: 'Test User',
password: 'hashed',
},
})
// With relations
const userWithPosts = await prisma.user.create({
data: {
email: 'author@example.com',
name: 'Author',
password: 'hashed',
posts: {
create: [
{ title: 'Post 1', content: 'Content 1' },
{ title: 'Post 2', content: 'Content 2' },
],
},
},
include: { posts: true },
})
// Many records
const users = await prisma.user.createMany({
data: [
{ email: 'a@test.com', name: 'A', password: 'hash' },
{ email: 'b@test.com', name: 'B', password: 'hash' },
],
})Read
// Find unique
const user = await prisma.user.findUnique({
where: { email: 'test@example.com' },
})
// Find first
const post = await prisma.post.findFirst({
where: { published: true },
})
// Find many
const users = await prisma.user.findMany({
where: { role: 'USER' },
orderBy: { createdAt: 'desc' },
take: 10,
skip: 0,
})
// With relations
const userWithPosts = await prisma.user.findUnique({
where: { id: userId },
include: {
posts: {
where: { published: true },
orderBy: { createdAt: 'desc' },
},
profile: true,
},
})
// Select specific fields
const emails = await prisma.user.findMany({
select: { email: true, name: true },
})Update
// Single record
const user = await prisma.user.update({
where: { id: userId },
data: { name: 'New Name' },
})
// Upsert
const user = await prisma.user.upsert({
where: { email: 'test@example.com' },
update: { name: 'Updated' },
create: { email: 'test@example.com', name: 'New', password: 'hash' },
})
// Many records
const updated = await prisma.user.updateMany({
where: { role: 'USER' },
data: { role: 'ADMIN' },
})Delete
// Single record
const user = await prisma.user.delete({
where: { id: userId },
})
// Many records
const deleted = await prisma.post.deleteMany({
where: { published: false },
})Filtering
// Complex where
const posts = await prisma.post.findMany({
where: {
AND: [
{ published: true },
{ title: { contains: 'prisma', mode: 'insensitive' } },
],
OR: [
{ author: { email: { endsWith: '@company.com' } } },
{ tags: { some: { name: 'featured' } } },
],
NOT: { authorId: excludedUserId },
},
})Database URL Examples
# PostgreSQL
DATABASE_URL="postgresql://user:password@localhost:5432/mydb?schema=public"
# MySQL
DATABASE_URL="mysql://user:password@localhost:3306/mydb"
# SQLite
DATABASE_URL="file:./dev.db"
# MongoDB
DATABASE_URL="mongodb+srv://user:password@cluster.mongodb.net/mydb"Introspection
# Generate schema from existing database
npx prisma db pullTroubleshooting
Reset everything
npx prisma migrate reset --forceClient out of sync
npx prisma generate
# Restart TypeScript serverMigration drift
npx prisma migrate diff \
--from-schema-datamodel prisma/schema.prisma \
--to-schema-datasource prisma/schema.prismaCheck database connection
npx prisma db execute --stdin <<< "SELECT 1"Production Checklist
- Run
npx prisma migrate deployin CI/CD - Don't use
db pushin production - Set
DATABASE_URLin environment - Enable connection pooling for serverless
- Use transactions for related operations
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

