to-dbml
Skill10 starsChanged 19 days agoMITView on GitHub
Turn ORM models, SQL, a live database, or an idea into a validated, versioned DBML entity model that opens on dbdiagram.io in one click.
In this repository25 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agents-md-improverSkill
- ai-tutorialSkill
- deassembleSkill
- excalidraw-diagramSkill
- find-overlapping-skillsSkill
- first-principlesSkill
- humanizerSkill
- improve-skillsSkill
- local-artifactSkill
- loom-transcriptSkill
- manage-contextSkill
- organize-skill-mcpSkill
- pair-consultSkill
- pair-optimizeSkill
- pair-ratchetSkill
- pr-classifySkill
- pr-reportSkill
- scan-sessions-and-learnSkill
- simplify-pythonSkill
- skill-flowSkill
- slack-commSkill
- socratesSkill
- step-by-stepSkill
- sub-consultSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Target: If the repo already holds a DBML file (*.dbml outside versions/, node_modules/, .git/), its directory and stem are the target.
- Distinctive: line 56
ORM models: read every model; map field types to the dialect's physical types.
- Distinctive: line 60
Done when: every table, column, PK, unique, index, FK (with its actions), and enum in the source is in the draft.
- Very specific: line 71
Done when: every entity has a key and every relationship a settled cardinality.
- Distinctive: line 75
Read references/dbml-subset.md, then write the draft outside the repo, under the target's basename (the scripts read the mode from the …
≈ “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.
Files
to-dbml
Write the entity model as one DBML snapshot of one source of truth: parsed by the official parser before it lands, laid out so two versions diff cleanly, archived on every real change, and one link away from a diagram. The file is regenerated, never maintained by hand.
Scripts are in scripts/ in this skill's base directory; run them with node (≥ 18; ≥ 22.14 also enables the dbdiagram render check). The first gate run installs @dbml/core 10.3.0 into ~/.cache/to-dbml/.
1. Resolve the run
/to-dbml [source] [--logical] [--push]
source | Branch |
a path: ORM model dir, migrations dir, .sql file | existing system |
db | existing system, live database |
quoted prose ("a marketplace where …") | idea (step 4) |
| omitted | existing system, auto-detected (step 3) |
Target. If the repo already holds a DBML file (*.dbml outside versions/, node_modules/, .git/), its directory and stem are the target; with several candidates, ask which. Otherwise docs/db/schema.dbml.
Each run writes exactly one file:
| Run | File |
| snapshot (default) | <dir>/<stem>.dbml |
--logical | <dir>/<stem>.logical.dbml |
| migration mode (step 2) | <dir>/<stem>.migration.dbml |
Migration mode and --logical are exclusive: if both apply, stop and say labels on a collapsed view would be ambiguous.
2. Detect migration mode
Migration mode is on when the run sees two schema states of the same system, A (what runs now) and B (what is rolling out):
- the user names two (
main..feature/x, "migrating from … to …"); - the database's applied migration state plus pending migration files;
- the current branch's schema sources differ from the default branch's;
- a database-evolution-lab run with A and B artifacts.
An explicit single source (one path, or db) is one state. When on, announce one line, migration mode: A = <…>, B = <…>, and read references/migration-labels.md before drafting.
3. Extract (existing system)
With several sources present, use the first in this precedence and record the rest as skipped: live DB → DDL/migrations → ORM models.
- Live DB: a connected database-schema tool or MCP first. Otherwise
npx -y -p @dbml/cli db2dbml <postgres|mysql|mssql|snowflake|bigquery|oracle> "$DSN"with the connection string held in an environment variable. - SQL DDL:
npx -y -p @dbml/cli sql2dbml <file.sql> --<postgres|mysql|mssql|snowflake|oracle>produces a first draft; then bring it to the conventions. - Migrations: replay them in order to the final state (in migration mode, to the A and B states).
- ORM models: read every model; map field types to the dialect's physical types; apply the ORM's implicit behavior (implicit PKs, default nullability, generated through tables).
Row reads on a live DB are read-only and bounded (LIMIT, aggregates, count(distinct …)) and feed only derived structure: enum value sets of low-cardinality columns, never-null-in-practice, 1-1 versus 1-n in practice. Each such inference carries note: 'observed: …'. Row values stay out of the file. Hosts, DSNs, users, and passwords stay out of every file; the Project note says only source: live DB (postgres).
Done when every table, column, PK, unique, index, FK (with its actions), and enum in the source is in the draft. Count tables and columns on both sides; the report states both counts.
4. Interview (idea)
Interview before drafting, in rounds: each round asks every question whose prerequisites are settled, numbered, each with your recommended answer; wait for the answers, then recompute. Ask only what shapes the schema:
- the entities and each one's identity (natural or surrogate key);
- the cardinality and optionality of every relationship;
- lifecycle and state fields (they become enums);
- tenancy and ownership boundaries.
Done when every entity has a key and every relationship a settled cardinality. Types, indexes, and defaults take the dialect's conventional choices without asking; every guess that remains carries note: 'assumed: …'. The Project note says source: interview (<date>).
5. Draft
Read references/dbml-subset.md, then write the draft outside the repo, under the target's basename (the scripts read the mode from the name).
--logical starts from the full physical model, then:
- drops
created_at,updated_at,deleted_at,created_by,updated_by,deleted_by, soft-delete flags (is_deleted), tenant and partition plumbing, and everyindexesblock; - collapses each pure join table (two FKs plus nothing but its own key) into one
<>Ref between the two sides; - keeps PKs, FKs, business columns, and enums.
6. Gate and write
node scripts/write.mjs <draft> <target> [--force]It runs the gate (scripts/validate.mjs: parser, the conventions, the migration rules, then dbdiagram validate), stamps the generated: line, and installs the file.
- Exit 1: fix every
ERRORand re-run. AnINFOfix is applied when it is true of the source (>?for a nullable FK) and left otherwise. - Exit 0,
no changes since …: nothing was touched. - Exit 3: the target was hand-edited or not made by this skill. Show the user the printed diff and ask: overwrite (re-run with
--force; the old file is still archived) or abort. - Exit 0,
wrote …: the previous file moved to<dir>/versions/<stem>_<YYYY-MM-DD_hh-mm-ss>.dbml.
7. Visualize
node scripts/embed-link.mjs <target> --copyIt prints a read-only dbdiagram.io link (no account; the DBML travels inside the link, so anyone holding it can read the schema) and puts the DBML on the clipboard for pasting into https://dbdiagram.io/d.
With --push:
npx -y dbdiagram auth status; when logged out, ask the user to run! npx -y dbdiagram auth login.- Diagram ids live in
<dir>/.dbdiagram-ids.json({"schema.dbml": "<id>"}). No id for this file means a first push: warn that Free-plan diagrams are public and push only after the user confirms, withnpx -y dbdiagram push <target> --name "<repo>/<file>" --json; record the returned id. - With an id:
npx -y dbdiagram push <target> --diagram-id <id> --jsonupdates the same diagram.
8. Report
- File written, or unchanged; the archived path.
- Source used and sources skipped; table and column counts, source versus file.
- Migration mode: A, B, and every
BREAKINGremoval. - Gate warnings, unapplied
INFOs, and a skipped render check with its reason. - The link ("DBML copied to clipboard"), and the diagram URL after
--push.
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
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.

