Coding Workflows Workflow Intermediate

AI Database Design Workflow

Design a schema on its data, not a hunch — model the entities and relationships, set the constraints that protect integrity, plan indexes around real queries, then document the schema and migration.

The problem

A data model is the hardest thing in an application to change later — every query, every feature, and every migration inherits its shape. Get the entities or the relationships wrong and you pay for it in joins, workarounds, and risky migrations for the life of the product. 'Ask AI for a schema' gives you a confident set of tables that ignores your access patterns, skips the constraints that protect integrity, and indexes nothing. This workflow designs the model on its real data: the entities and how they relate, the constraints that keep it honest, the indexes the actual queries need, and a documented migration — before the schema is set in production.

Recommended workflow

Each step uses an existing NewPrompt tool, pre-filled by a matching resource. Open the resource to read it, or jump straight into the tool with the inputs ready.

  1. Model the entities and relationships

    Start with the data, not the tables. Anchor the model as an architect and map the real entities, their attributes, and how they relate — one-to-many, many-to-many, the optional versus the required — before anything becomes a column.

    Outcome The core entities and their relationships mapped to the real domain.
  2. Set the constraints that protect integrity

    Decide what keeps the data honest: keys, uniqueness, nullability, foreign-key rules, and the invariants the application must never violate. Work them one decision at a time — the constraints are what stop bad data, not the code on top.

    Outcome Keys, constraints, and integrity rules decided and justified.
  3. Plan indexes around real queries

    Indexes follow access patterns, not guesses. Lay out the queries the app will actually run, then plan the indexes that serve them — and notice the ones missing that would turn a feature into a table scan.

    Outcome Indexes planned against the queries the application really runs.
  4. Document the schema and migration

    Capture the final model and the reasoning — why the relationships are shaped this way, what the constraints protect — plus the migration plan to get there, so the build and future-you start from a documented design.

    Outcome The schema and its migration documented, reasoning included.

Expected outcome

A database schema designed on its real data — entities and relationships modeled, integrity constraints decided, indexes planned around the actual queries, and the whole thing documented with a migration plan — so you build on a deliberate model instead of a confident guess you'll be migrating around for years.

Best for

  • Designing a new schema before writing migrations
  • Modeling entities, relationships, and integrity constraints deliberately
  • Planning indexes around the queries an app will really run

Not for

  • Tuning a slow query on an existing schema — use a SQL optimization prompt
  • Designing the API over the data — use the AI API Design Workflow
  • Deciding the system's overall architecture — use the AI Project Architecture Workflow

FAQ

Database design workflow vs optimizing a SQL query?

SQL optimization speeds up one query against a schema that already exists. This workflow designs that schema first — modeling entities and relationships, deciding integrity constraints, then planning indexes around the queries the app really runs. Optimization is what you do later, inside the model these four steps produce, not a substitute for it.

Should I design the database schema or the API first?

Usually the schema first — the entities, relationships, and constraints this workflow models are the data your API exposes, so shaping them well gives the interface something honest to sit on. Run this to document the schema and migration, then hand that model to the AI API Design Workflow to design the contract over it.

Will the AI just give me a generic schema?

Only if you let it. The point of the steps is to force the model onto your real entities, access patterns, and invariants — so the schema fits your domain instead of a textbook example. The modeling calls stay yours.

What does the AI database design workflow produce?

A documented schema built on real data: the entities and relationships mapped to your domain, the keys and integrity constraints decided and justified, indexes planned against the queries the app runs, plus a migration plan and the reasoning behind the shape. Step four captures all of it so the build starts from a deliberate design.

How do I run the AI database design workflow?

Work the four steps in order in your own AI tool: model the entities and relationships, set the constraints that protect integrity, plan indexes around real queries, then document the schema and migration. Each step links a prompt and resource; you run the prompts and own every modeling decision. Budget 45 to 75 minutes.

What do I need before starting the database design workflow?

The data your application handles and the queries it will run. Step one models entities from that domain, and step three plans indexes against those real access patterns — so the more you know about what the app reads and writes, the sharper the schema. You don't need existing tables; this designs them before the migration.

Part of these projects

Complete build journeys that include this workflow as a stage.

Guides for this workflow

Recommended next workflow

Tip: Each step's resource opens its tool pre-filled — start at step one and carry the output forward.