agentleFS
JoaoEquerJoaoEquer/Oficina/skills/prisma-schema-conventions/SKILL.md

prisma-schema-conventions

Skill2 starsChanged 25 days agoMITView on GitHub

Data modeling conventions for Prisma + PostgreSQL in multi-tenant systems — workspace isolation, numeric criticality, idempotent recurrence, document versioning by lineage and decoupled audit via a queue in Postgres itself. Use whenever creating or changing schema.prisma, designing new entities, planning migrations or discussing data modeling in any project on this stack.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every business entity carries a workspaceId (row-level isolation, single database).

    line 12
  2. Distinctive:

    Never overwrite a file. Each version is a new row, grouped by a lineage id:

    line 47

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Prisma schema conventions

Modeling decisions locked in by production experience. They apply to every new entity unless an explicit, recorded decision says otherwise.

1. Multi-tenancy: workspaceId on every entity

Every business entity carries a workspaceId (row-level isolation, single database). Isolation is enforced at the data layer — every query filters by workspace — and the id always comes from the authenticated context, never from client input.

model Task {
  id          String   @id @default(uuid())
  workspaceId String
  workspace   Workspace @relation(fields: [workspaceId], references: [id])
  // ...
  @@index([workspaceId])
}

Watch out: confirm early with the architect whether the project is actually multi-tenant. A mismatch between the data model document (single-tenant) and the commercial document (multi-tenant) is a classic error — resolve it BEFORE the first production migration, not after.

2. Criticality / priority: numeric scale, never boolean

criticality Int (e.g. 1–5). A boolean ("critical yes/no") doesn't survive the first meeting where the client asks for "medium priority". If the model document shows boolean on one entity and integer on another, treat it as an inconsistency to resolve — model as Int and flag it.

3. Idempotent recurrence

Recurring tasks/events are generated from a template, with a composite unique key (templateId + target date):

model Task {
  // ...
  templateId String?
  targetDate DateTime?
  @@unique([templateId, targetDate])
}

The recurrence generator can run any number of times (duplicated cron, retry, reprocessing) without creating duplicates. Idempotency by design, not by application logic.

4. Documents versioned by lineage

Never overwrite a file. Each version is a new row, grouped by a lineage id:

model Document {
  id        String  @id @default(uuid())
  lineageId String              // groups all versions of the "same" document
  version   Int
  active    Boolean @default(true) // only one active version per lineage
  // ...
  @@unique([lineageId, version])
}

5. Decoupled audit (queue in Postgres itself)

Auditing must not slow down the main operation nor take it down if it fails. The pattern: the business transaction writes an event to a queue table (AuditQueue); a separate worker consumes the queue and materializes the audit record. No Redis, no external queue — Postgres handles it until proven otherwise (the justified-complexity rule).

6. Dates in UTC, always

Database in UTC, timezone conversion only at the edge (presentation). Prisma's DateTime is UTC-friendly; the sin is application code creating dates in local time.

7. Soft delete by default

deletedAt DateTime? on business entities. Hard delete only with a recorded decision (e.g. data-protection requirements such as LGPD/GDPR for personal data).

Before any production migration

Mandatory checklist:

  • Schema checked against the data model document (source of truth)
  • Divergences between documents resolved with the architect and recorded
  • Multi-tenancy confirmed (item 1)
  • Ambiguous field types confirmed (item 2)
  • Migration reviewed (descriptive name, no accumulated migrate dev garbage)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.