Skip to content
Back to skills

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
databasestypescriptbashsqlapidatabaseperformance

Works with

  • api
  • mcp

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned November 24, 2026

npx -y skills add iDorgham/Workspace-Factory --skill database --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Database?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Database
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/idorgham-database/badge)](https://www.skillsdirectory.com/skills/idorgham-database)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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.py334 B
  • manifest.yaml164 B
  • skill.md3.1 KB
  • skill.md.meta.json793 B
  • tests/test_core.py278 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in databases →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.