From ring-pm-team
Generates a stack-native physical data model (DDL or Prisma schema) from an OpenAPI spec and TRD. Use for large features with persistent data, after API contracts are validated.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ring-pm-team:designing-data-modelThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- OpenAPI spec passed Gate 4 validation (or Gate 4 SKIPPED for features with no API surface)
Runs before: ring:pinning-dependency-versions Runs after: ring:designing-api-contracts
The deliverable is a REAL, stack-native schema file — DDL that becomes migrations, not markdown tables. The DDL IS the deliverable: CREATE TABLE, indexes, and constraints are required, not forbidden.
See shared-patterns/standards-discovery.md for the complete workflow.
If docs/pre-dev/{feature}/api-standards-ref.md exists, auto-detect naming convention.
If api-standards-ref.md EXISTS: AskUserQuestion: "How should database fields be named?"
If api-standards-ref.md DOES NOT EXIST: AskUserQuestion: "How should database fields be named?"
db-standards-ref.mdOption: Convert to snake_case — apply automatic rules:
Option: Keep same — copy field names without modification.
Option: Load from doc — WebFetch or read, extract field definitions, save to db-standards-ref.md.
Determine the schema format from the TopologyConfig (research.md frontmatter) plus repo manifests:
| Evidence | Format | Output File |
|---|---|---|
language: golang in TopologyConfig, go.mod present, Postgres in TRD/stack | PostgreSQL DDL | docs/pre-dev/{feature}/schema.sql |
prisma/ directory or @prisma/client in package.json | Prisma schema | docs/pre-dev/{feature}/schema.prisma |
| Other stack with a native schema format (e.g., Drizzle, SQLAlchemy) | That stack's native format | docs/pre-dev/{feature}/schema.{ext} |
| Undetectable / greenfield | PostgreSQL DDL (Lerian default) | docs/pre-dev/{feature}/schema.sql |
Postgres is the Lerian default. When in doubt, write schema.sql.
| Phase | Activities |
|---|---|
| 2. Entity Identification | From OpenAPI spec (Gate 4 schemas) and TRD (Gate 3): identify all persisted entities; determine aggregate boundaries; map ownership per service |
| 3. Schema Authoring | Write the schema file: tables/models with typed columns, PK/FK constraints, NOT NULL, CHECK/enum constraints, indexes for known query patterns; apply naming from Phase 0 |
| 4. Validation | Run the Gate 5 checklist; verify the file parses (e.g., psql --dry-run-style review or npx prisma validate) |
The schema file MUST be migration-ready:
uuid default at Lerian), created_at/updated_at timestamps (UTC, timestamptz)ON DELETE behavior — no implicit cascade decisionsCHECK constraints or native enums (ACTIVE, INACTIVE, ...)deleted_at) only where the TRD requires retention-- owner: {service-name} (or /// owner: in Prisma). Multi-service writes to one table are a design smell — flag them.ER diagram, if useful, goes in a comment header at the top of the schema file or in the TRD — there is no separate data-model.md appendix.
-- owner: accounts-service
CREATE TABLE accounts (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
name varchar(255) NOT NULL,
status varchar(16) NOT NULL CHECK (status IN ('ACTIVE','INACTIVE','BLOCKED')),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX idx_accounts_status ON accounts (status);
| Category | Requirements |
|---|---|
| Valid schema | File parses in its native tooling; format matches detected stack; migration-ready (no pseudo-DDL) |
| Entity Completeness | Every persisted OpenAPI schema has a table/model; ownership comment per entity; lifecycle states constrained |
| Schema Quality | Precise column types; NOT NULL/CHECK/unique constraints explicit; naming consistent with db-standards-ref.md |
| Relationships | All FKs declared with explicit ON DELETE behavior; cardinality matches the TRD; join/lookup indexes present |
| API Alignment | Every column maps to an OpenAPI schema field per the naming strategy (or is documented as internal-only) |
Gate Result: ✅ PASS → Dependency Map | ⚠️ CONDITIONAL (fix naming/missing indexes) | ❌ FAIL (missing entities or non-parsing schema)
| Structure | Files Generated |
|---|---|
| single-repo | docs/pre-dev/{feature}/schema.sql (or .prisma) |
| monorepo | Root docs/pre-dev/{feature}/schema.sql (or .prisma) |
| multi-repo | {backend.path}/docs/pre-dev/{feature}/schema.sql (or .prisma) + frontend copy |
npx claudepluginhub p/lerianstudio-ring-pm-team-pm-teamGenerates data models and staged, shippable SQL forward/rollback migrations from feature specs. Stack-agnostic, follows repo conventions.
Designs database schemas—tables, columns, types, indexes, constraints, relationships—from domain descriptions. Outputs DDL, ORM configs, migrations; detects stack like Prisma/Drizzle or defaults to PostgreSQL SQL.
Design and build database schema — tables, columns, types, indexes, constraints, relationships. Given a domain description, output the schema and write the files. Use when asked to "design schema", "database design", "create tables", or "data model".