prisma-data-model
Understanding the Prisma schema, core entities, and database operations.
When & Why to Use This Skill
This Claude skill provides expert guidance on managing Prisma schemas, core entity relationships, and database operations. It ensures data integrity through multi-tenant isolation, implements soft-delete strategies, and optimizes Prisma ORM usage for scalable application development.
Use Cases
- Designing and extending Prisma schemas for multi-tenant applications to ensure strict data isolation.
- Implementing soft-delete logic across database queries to maintain data history while keeping active datasets clean.
- Managing complex hierarchical relationships between Tenants, Projects, Contracts, and Invoices.
- Executing database migrations and client generation commands safely across development and production environments.
| name | prisma-data-model |
|---|---|
| description | Understanding the Prisma schema, core entities, and database operations. |
Prisma Data Model
This skill ensures correct usage of the database schema and Prisma commands.
Core Entities
The system relies on the following core models defined in prisma/schema.prisma:
1. Tenant
The top-level organizational unit.
- Relationships:
- Has many
Projects. - Has many
Environments. - Has many
Users.
- Has many
2. Project
A specific engagement or workspace within a Tenant.
- Belongs to:
Tenant. - Has many:
Contracts,Invoices.
3. Contract
Legal agreements associated with a Project.
4. Invoice
Billing records linked to a Project.
5. User
System users with access to Tenants.
Key Relationships
- Hierarchy:
Tenant->Project-> (Contract,Invoice). - Isolation: Queries should almost always filter by
tenantIdto ensure data isolation.
Soft Deletes
The system uses a "Soft Delete" strategy.
- Field:
deletedAt(DateTime, nullable). - Logic:
- If
deletedAtisnull, the record is active. - If
deletedAtis set, the record is considered deleted.
- If
- Querying: Always include
where: { deletedAt: null }in queries unless explicitly auditing deleted items.
Commands
- Generate Client:
npx prisma generate(Run after schema changes). - Migrate DB:
npx prisma migrate deploy(For production) ornpx prisma migrate dev(For development).