Back to skills
SKILL.md
Database
ASecurity- **DB**: PostgreSQL 15+ - **ORM**: Prisma 5.x - **Schema**: `packages/db/prisma/schema.prisma` - **Migrations**: `packages/db/prisma/migrations/`
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added November 24, 2026
Works with
Security analysis
100/100Pro scans all 5 files and shows the line behind each finding
npx -y skills add iDorgham/Workspace-Factory --skill database --agent claude-codeAre you the author of Database?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/idorgham-database)---
type: Skill
subagents: [core-validator, integrity-bot]
agents: [master-guide, swarm-router]
dependencies: [core-orchestration, global-sync]
version: 1.0.0
---
# Workspace Factory Database
## Stack
- **DB**: PostgreSQL 15+
- **ORM**: Prisma 5.x
- **Schema**: `packages/db/prisma/schema.prisma`
- **Migrations**: `packages/db/prisma/migrations/`
## Required Patterns
### Multi-tenant (always)
```typescript
where: {
organizationId: auth.orgId,
deletedAt: null,
}
```
### Soft delete (always)
```typescript
// Query: filter deleted
where: { deletedAt: null }
// Delete: set deletedAt
await prisma.gate.update({
where: { id },
data: { deletedAt: new Date() },
});
```
### New model checklist
- `organizationId` + `@@index([organizationId])` for tenant models
- `deletedAt DateTime?` + `@@index([deletedAt])` for mutable models
- `createdAt`, `updatedAt` timestamps
- `@default(cuid())` for ids
## Migration Workflow
```bash
cd packages/db
npx prisma generate # After schema edit
npx prisma migrate dev --name add_field
npx prisma db push # Dev only, no migration
npx prisma studio
```
## MCP: Prisma-Local
When **Prisma-Local** MCP is enabled, use its tools for:
- **migrate-dev** — Create and apply migration (LLM provides migration name)
- **migrate-status** — Check migration state
- **Prisma-Studio** — Open Prisma Studio via `prisma studio`
## Core Models
| Model | Purpose |
|-------|------
## 🌍 Regional Calibration (MENA Context)
- **Cultural Alignment:** Ensure all logic respects regional business etiquette and MENA market expectations.
- **RTL Compliance:** Logic must explicitly handle Right-to-Left (RTL) flow where relevant.
## 🛡️ Critical Failure Modes (Anti-Patterns)
- **Anti-Pattern:** Generic Output -> *Correction:* Apply sector-specific professional rules from RULE.md.
- **Anti-Pattern:** Global-Only Logic -> *Correction:* Verify against MENA regional calibration.
---
|
| Organization | Multi-tenant root |
| Project | Sub-grouping |
| User | Auth, RBAC |
| Gate | Access points |
| QRCode | Access codes (HMAC signed) |
| ScanLog | Immutable audit trail (scanUuid dedup) |
| Unit | Residential units (Phase 2) |
## Query Examples
### Find many with org scope
```typescript
const gates = await prisma.gate.findMany({
where: { organizationId: orgId, deletedAt: null },
include: { project: true },
orderBy: { createdAt: 'desc' },
});
```
### Transaction
```typescript
await prisma.$transaction(async (tx) => {
await tx.qRCode.update({
where: { id },
data: { scanCount: { increment: 1 } },
});
await tx.scanLog.create({ data: { ... } });
});
```
### Aggregation
```typescript
const stats = await prisma.scanLog.groupBy({
by: ['status'],
where: { organizationId: orgId, createdAt: { gte: start, lte: end } },
_count: true,
});
```
## Performance
- Use `select` for large result sets
- `createMany` for bulk inserts
- Add `@@index` on frequently queried fields
- Connection pool in DATABASE_URL
## Input Validation
Use Zod for API input; Prisma for DB constraints.
**Reference:** `packages/db/prisma/schema.prisma`, `packages/db/prisma/seed.ts`Files in this skill
- core.py
- manifest.yaml
- skill.md
- skill.md.meta.json
- tests/test_core.py
Attribution
Related skills
View all in databases →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.