--- name: schema-design description: Hub-and-spoke pipeline that converts "I need a database for app X" into a designed relational schema, a generated first migration, and optional seed/fixture data — via pure-click decisions across five phases. Emits SQL DDL, a kei-migrate-shaped migrations directory, and a library/ORM pick; never writes production secrets. argument-hint: --- # Schema-Design — Relational Schema & Migration Pipeline (index) ## When to use - Designing a relational database schema for a new or evolving app (Postgres, SQLite). - Generating SQL DDL, migrations directory, and optional seed/fixture data from a click-driven design session. - Choosing the right ORM, migration tool, and indexing strategy before writing any code. > See `_blocks/pipeline-5phase-template.md` for the 5-phase wizard contract > and `_blocks/rule-pure-click-contract.md` for the AskUserQuestion rule. > Skill-specific phase tables are inline below. You are converting "I need a database for app X" into a concrete, reviewable design: chosen DB + ORM, entity list + relations, SQL DDL with indexes and FKs, a scaffolded migrations directory with the first migration, and (if asked) seed data for tests and dev. Every decision is a click; the only typed inputs are the one-line app description in Phase 1 and the entity list in Phase 2. This skill does NOT run migrations or touch production. It produces files under `db/schema.sql`, `migrations/_init.sql` (+ `.down.sql`), and optionally `db/seed.sql`. Applying them is a separate command (`kei-migrate up`), owned by the project's code-implementer. The skill reads the five database blocks heavily — every phase references at least one of them: - `_blocks/db-postgres.md` — PG 17 patterns, indexing, pooling. - `_blocks/db-sqlite.md` — single-node / edge pragmas. - `_blocks/db-sqlx.md` — Rust query + migration flow. - `_blocks/db-drizzle.md` — TS schema-first ORM. - `_blocks/db-migration-hygiene.md` — universal up/down + checksum rules. Primitive used for scaffolding: `_primitives/_rust/kei-migrate` (universal Postgres / SQLite / MySQL migration runner — create + up + down + status). --- ## Pipeline overview (5 phases, ≥5 AskUserQuestion calls) | Phase | File | Purpose | AskUserQuestion | |---|---|---|---| | 1 | [phase-1-intake.md](phase-1-intake.md) | DB, ORM, scale, style, migration control | 5× (batched) | | 2 | [phase-2-entities.md](phase-2-entities.md) | Entity list + relations matrix | 1× | | 3 | [phase-3-schema.md](phase-3-schema.md) | Generate DDL + indexes + FKs + constraints; review/revise | 1× | | 4 | [phase-4-migrations.md](phase-4-migrations.md) | Scaffold `migrations/` + first migration + kei-migrate wiring | 1× | | 5 | [phase-5-seed.md](phase-5-seed.md) | Optional seed + test fixtures | 1× | Minimum AskUserQuestion count across a full session: **9** (5 in Phase 1 + 1 each in Phases 2–5). Exceeds the ≥5 hub-and-spoke contract. --- ## Variables the pipeline produces | Name | Set in | Meaning | |---|---|---| | `INTAKE` | Phase 1 | one-paragraph app description (verbatim) | | `DB` | Phase 1 | Postgres / SQLite / MySQL | | `ORM` | Phase 1 | none (raw SQL) / Drizzle / SQLx / Prisma / SQLAlchemy | | `SCALE` | Phase 1 | solo-prototype / team-dev / production-multi-replica | | `STYLE` | Phase 1 | schema-first (SQL → types) / code-first (types → SQL) | | `MIGCTL` | Phase 1 | manual / auto-on-deploy / hybrid (manual prod, auto dev) | | `ENTITIES` | Phase 2 | list of entities + fields + relations matrix | | `DDL` | Phase 3 | generated SQL (tables, indexes, FKs, constraints) | | `MIGDIR` | Phase 4 | path of migrations dir + first migration filenames | | `SEED` | Phase 5 | seed-data plan (or "skipped") | --- ## Final report (emit after Phase 5) ``` === SCHEMA-DESIGN REPORT === App: ... DB / ORM: + (style: