Docs → DBML
Read the project's documentation (requirements, specs, existing notes) and express
the data model as a DBML file.
Inputs
Documentation the user points to (specs, ADRs, an entity list, or a prose
description). If none is given, ask which document to model.
Output
docs/data-models/<name>.dbml — one DBML file. Never modify unrelated files.
DBML syntax (the subset to emit)
Table users {
id integer [primary key]
username varchar [not null, unique]
role varchar [note: 'admin | member']
created_at timestamp [default: `now()`]
Note: 'Application users'
}
Table posts {
id integer [primary key]
user_id integer [not null]
status varchar
Indexes {
(user_id, status)
}
}
// Relationships: > many-to-one, < one-to-many, - one-to-one
Ref: posts.user_id > users.id
Enum order_status {
pending
shipped
delivered
}
Rules:
- Every table has a primary key (
[primary key] on a column, or
indexes { (a,b) [pk] } for composite).
- Column settings go in
[ ]: not null, unique, primary key,
default: ..., note: '...'. Wrap SQL/function defaults in backticks:
default: `now()`.
- Foreign keys: declare a
Ref: line (or inline [ref: > users.id]). Use >
(many-to-one), < (one-to-many), - (one-to-one).
- Use
Enum blocks for closed value sets and reference them as the column type.
- Quote table/column names containing spaces or reserved words with double quotes.
Procedure
- Extract entities → tables, attributes → columns (pick sensible types:
integer, varchar, text, boolean, timestamp, decimal, uuid).
- Identify relationships from the docs and emit
Ref: lines.
- Add a
Note: on each table summarizing its purpose; add note: on
non-obvious columns.
- Write
docs/data-models/<name>.dbml.
Validation
- Every
Ref: references a table.column that exists in the file.
- Every table has a primary key.
- If the
@dbml/cli tool is available, run dbml2sql <file> --postgres and fix
any parse error it reports.
The DBML file describes the model; it does not replace the migrations. When the
project already has an ORM schema, derive the DBML from that schema and say which
one is the source of truth.
1---2name: docs-to-dbml3description: Produce a DBML database schema from documentation, requirements, or an existing data model. Use when the user wants a DBML (dbdiagram.io) file describing tables, columns, and relationships, or mentions DBML / ER diagram / data model.4license: MIT5---67# Docs → DBML89Read the project's documentation (requirements, specs, existing notes) and express10the data model as a [DBML](https://dbml.dbdiagram.io/docs/) file.1112## Inputs1314Documentation the user points to (specs, ADRs, an entity list, or a prose15description). If none is given, ask which document to model.1617## Output1819`docs/data-models/<name>.dbml` — one DBML file. Never modify unrelated files.2021## DBML syntax (the subset to emit)2223```dbml24Table users {25 id integer [primary key]26 username varchar [not null, unique]27 role varchar [note: 'admin | member']28 created_at timestamp [default: `now()`]2930 Note: 'Application users'31}3233Table posts {34 id integer [primary key]35 user_id integer [not null]36 status varchar37 Indexes {38 (user_id, status)39 }40}4142// Relationships: > many-to-one, < one-to-many, - one-to-one43Ref: posts.user_id > users.id4445Enum order_status {46 pending47 shipped48 delivered49}50```5152Rules:53- Every table has a **primary key** (`[primary key]` on a column, or54 `indexes { (a,b) [pk] }` for composite).55- Column settings go in `[ ]`: `not null`, `unique`, `primary key`,56 `default: ...`, `note: '...'`. Wrap SQL/function defaults in backticks:57 `` default: `now()` ``.58- Foreign keys: declare a `Ref:` line (or inline `[ref: > users.id]`). Use `>`59 (many-to-one), `<` (one-to-many), `-` (one-to-one).60- Use `Enum` blocks for closed value sets and reference them as the column type.61- Quote table/column names containing spaces or reserved words with double quotes.6263## Procedure64651. Extract entities → tables, attributes → columns (pick sensible types:66 `integer`, `varchar`, `text`, `boolean`, `timestamp`, `decimal`, `uuid`).672. Identify relationships from the docs and emit `Ref:` lines.683. Add a `Note:` on each table summarizing its purpose; add `note:` on69 non-obvious columns.704. Write `docs/data-models/<name>.dbml`.7172## Validation7374- Every `Ref:` references a `table.column` that exists in the file.75- Every table has a primary key.76- If the `@dbml/cli` tool is available, run `dbml2sql <file> --postgres` and fix77 any parse error it reports.7879The DBML file describes the model; it does not replace the migrations. When the80project already has an ORM schema, derive the DBML from that schema and say which81one is the source of truth.