
prisma-data-model
by ArtisanClarinets
SKILL.md
name: prisma-data-model description: Understand the specific data model, entities, and database operations for Project SENTINEL. Use when writing database queries, creating migrations, or explaining the data architecture.
Prisma Data Model
This skill provides context on the database schema defined in prisma/schema.prisma. It ensures data integrity, multi-tenant isolation, and secure database operations across the platform.
Quick Start
Implement a data change in 4 steps:
- Update Schema: Modify
prisma/schema.prismawith new models or fields. - Generate Client: Run
npm run prisma:generateto update the types. - Create Migration: Run
npm run prisma:migrateto apply changes to the database. - Update Zod Schemas: Ensure corresponding Zod schemas in
lib/validations/are updated.
// Example: Tenant-scoped query with soft-delete check
const projects = await prisma.project.findMany({
where: {
tenantId: user.tenantId,
deletedAt: null,
},
select: {
id: true,
name: true,
status: true,
},
});
Core Entities
- Tenant: The top-level organization unit. Everything belongs to a Tenant (directly or indirectly).
- Identified by
slug. - Owns
Environments,Projects,Contracts,Invoices.
- Identified by
- Project: A specific engagement or scope of work within a Tenant.
- Has
Assignments(Users) andTimeEntries.
- Has
- User: A global user entity with
RoleAssignments(RBAC) scoped to Global, Tenant, or Project levels.- Includes
mfaSecretfor enhanced security.
- Includes
- Contract: Legal agreements with versioning (
ContractVersion) and e-signature support. - AuditLog: Immutable record of all privileged actions (
actorId,action,resource,diff).
Key Logic & Constraints
1. Multi-tenancy & Isolation
Most operational entities are explicitly scoped to a tenantId. Mandatory: Always include tenantId in queries to prevent cross-tenant data leakage.
2. Soft Deletes
Models support soft deletes via deletedAt, deletedBy, and deleteReason.
- Rule: Always filter
where: { deletedAt: null }unless explicitly retrieving archived data.
3. RBAC Enforcement
Implemented via RoleAssignment. Permissions are checked at the API level but must be reflected in data access patterns.
Database Operation Workflows
Adding a New Model
Step 1: Define the Model
Ensure the model includes tenantId (if applicable) and soft-delete fields.
Step 2: Establish Relationships
Use Prisma's relation syntax to link models (e.g., @relation(fields: [tenantId], references: [id])).
Step 3: Audit Integration
Ensure any mutation to the new model is wrapped in an audit-logging mechanism (e.g., adminMutation).
// Integration with Audit Logging
await prisma.auditLog.create({
data: {
action: "create_resource",
resource: "new_model",
actorId: user.id,
diff: JSON.stringify({ after: newData }),
},
});
Handling Migrations
- Development: Use
npm run prisma:migratefor interactive migrations. - Production: Use
npx prisma migrate deployin CI/CD pipelines to apply pending migrations safely.
Advanced Patterns
Transactional Integrity
Use prisma.$transaction for operations involving multiple related models (e.g., creating an Invoice and updating InvoiceSequence).
Performance Optimization
Use select to retrieve only necessary fields, avoiding include where possible to reduce query complexity and data transfer.
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です