git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/handler-db-prisma" ~/.claude/skills/majiayu000-claude-skill-registry-handler-db-prisma && rm -rf "$T"
skills/data/handler-db-prisma/SKILL.mdPrisma Database Handler Skill
<CONTEXT> You are the handler-db-prisma skill, the Prisma-specific implementation for database operations. You are invoked by other skills (db-initializer, migration-deployer, etc.) when the configured migration tool is Prisma.This handler translates generic database operations into Prisma-specific CLI commands and manages Prisma client interactions. </CONTEXT>
<CRITICAL_RULES>
- NEVER execute Prisma commands directly - ALWAYS use scripts
- ALWAYS validate Prisma CLI is installed before operations
- ALWAYS check prisma/schema.prisma exists for schema operations
- ALWAYS output start/end messages for visibility
- ALWAYS return structured JSON responses
- NEVER expose database credentials in logs
- ALWAYS validate connection string format
- PRODUCTION SAFETY: Run
for production (notprisma migrate deploy
) </CRITICAL_RULES>prisma migrate dev
Example Request
</INPUTS> <WORKFLOW>{ "operation": "create-database", "parameters": { "database_name": "myapp_dev", "database_url_env": "DEV_DATABASE_URL", "working_directory": "/mnt/c/GitHub/myorg/myproject" } }
Follow the workflow files in
workflow/ for operation-specific instructions:
- Database creation workflowworkflow/create-database.md
- Migration generation workflowworkflow/generate-migration.md
- Migration deployment workflowworkflow/apply-migration.md
- Status checking workflowworkflow/check-status.md
High-level process:
- Output start message with operation
- Validate Prisma CLI is installed
- Set working directory context (CLAUDE_DB_CWD)
- Load configuration
- Validate parameters for operation
- Execute Prisma-specific operation via scripts
- Validate operation results
- Output end message with results
- Return structured JSON response
Prisma CLI Commands Used:
- Initialize Prisma in projectprisma init
- Generate Prisma Clientprisma generate
- Create and apply migration (dev)prisma migrate dev
- Apply migrations (production)prisma migrate deploy
- Check migration statusprisma migrate status
- Resolve migration issuesprisma migrate resolve
- Push schema to database (prototyping)prisma db push
- Pull schema from database (introspection)prisma db pull
<COMPLETION_CRITERIA> You are complete when:
- Prisma CLI availability validated
- Operation-specific validation passed
- Prisma command executed successfully
- Results validated
- Success message output
- Structured JSON response returned
If any step fails:
- Log detailed error with Prisma output
- Suggest corrective actions
- Return error response with recovery steps </COMPLETION_CRITERIA>
Output structured messages:
Start:
🎯 STARTING: Prisma Handler Operation: create-database Database: myapp_dev ───────────────────────────────────────
During execution, log key steps:
- ✓ Prisma CLI found (version 5.x.x)
- ✓ prisma/schema.prisma exists
- ✓ Database URL validated
- ✓ Creating database myapp_dev
- ✓ Running prisma migrate dev --name init
- ✓ Migration table created: _prisma_migrations
- ✓ Prisma Client generated
End (success):
✅ COMPLETED: Prisma Handler Operation: create-database Database: myapp_dev Migrations Applied: 1 (init) Status: Ready ─────────────────────────────────────── Next: Add models to prisma/schema.prisma
Return JSON:
Success:
{ "status": "success", "operation": "create-database", "handler": "prisma", "result": { "database_name": "myapp_dev", "prisma_version": "5.8.0", "schema_path": "prisma/schema.prisma", "migrations_applied": 1, "migration_table": "_prisma_migrations", "client_generated": true }, "message": "Database created and Prisma initialized successfully" }
Error:
</OUTPUTS>{ "status": "error", "operation": "create-database", "handler": "prisma", "error": "Prisma CLI not found", "recovery": { "suggestions": [ "Install Prisma: npm install -D prisma @prisma/client", "Or use different migration tool: /faber-db:init --migration-tool typeorm" ], "prisma_docs": "https://www.prisma.io/docs/getting-started" } }
<ERROR_HANDLING>
Common errors and handling:
Prisma CLI Not Found:
{ "status": "error", "error": "Prisma CLI not found in project", "recovery": { "suggestions": [ "Install Prisma: npm install -D prisma @prisma/client", "Verify package.json has prisma in devDependencies", "Run npm install to install dependencies" ] } }
Schema File Missing:
{ "status": "error", "error": "prisma/schema.prisma not found", "recovery": { "suggestions": [ "Initialize Prisma: npx prisma init", "Or create schema file manually in prisma/ directory", "See: https://www.prisma.io/docs/concepts/components/prisma-schema" ] } }
Migration Failed:
{ "status": "error", "error": "Migration failed: duplicate column name", "prisma_output": "Error: P3005 The database schema is not empty...", "recovery": { "suggestions": [ "Review migration file: prisma/migrations/.../migration.sql", "Check for conflicting changes", "Reset database: npx prisma migrate reset (WARNING: data loss)", "Or manually fix schema and retry" ] } }
Connection Failed:
{ "status": "error", "error": "Database connection failed", "prisma_output": "Error: P1001 Can't reach database server...", "recovery": { "suggestions": [ "Verify DATABASE_URL environment variable is set correctly", "Check database server is running", "Test connection: psql $DATABASE_URL", "Verify firewall rules allow connection" ] } }
</ERROR_HANDLING>
<DOCUMENTATION> Document operations by: 1. Logging Prisma CLI version and commands executed 2. Recording migration files created 3. Outputting detailed start/end messages 4. Capturing Prisma CLI output for debugging 5. Returning structured results with file paths </DOCUMENTATION> <INTEGRATION>Prisma CLI Integration
All operations execute Prisma CLI commands via scripts:
Scripts Location:
skills/handler-db-prisma/scripts/
- Database initializationcreate-database.sh
- Migration generationgenerate-migration.sh
- Migration deploymentapply-migration.sh
- Status checkingcheck-status.sh
- Schema validationvalidate-schema.sh
Prisma Files Managed:
- Database schema definitionprisma/schema.prisma
- Migration historyprisma/migrations/
- Connection strings (not committed).env
- Generated Prisma Clientnode_modules/.prisma/client/
Environment Variables
Prisma uses
DATABASE_URL environment variable:
export DATABASE_URL="postgresql://user:password@localhost:5432/myapp_dev"
This handler maps environment-specific variables to
DATABASE_URL before Prisma operations:
</INTEGRATION># Map DEV_DATABASE_URL to DATABASE_URL for Prisma export DATABASE_URL="${DEV_DATABASE_URL}" npx prisma migrate dev
Operation-Specific Notes
Create Database
- Runs
if schema doesn't existprisma init - Creates database using
prisma migrate dev --name init - Generates Prisma Client with
prisma generate - Validates migration table exists
Generate Migration
- Runs
for devprisma migrate dev --name <name> - Creates migration file in
prisma/migrations/<timestamp>_<name>/ - Includes both
and metadatamigration.sql
Apply Migration (Production)
- Uses
(NOTprisma migrate deploy
)migrate dev - Applies pending migrations only
- No interactive prompts
- Idempotent (safe to run multiple times)
Check Status
- Runs
prisma migrate status - Shows pending migrations
- Shows applied migrations
- Detects drift between schema and database
Rollback Migration
- Prisma doesn't have built-in rollback
- Must manually write down migrations
- Or use custom rollback logic with raw SQL
Prisma Versions Supported
Minimum Version: Prisma 4.0.0 Recommended Version: Prisma 5.x.x Tested Version: Prisma 5.8.0
Version checked at runtime and reported in output.