The assistant for ER diagrams

Ask the assistant, or your own AI app, to design a database schema, change one, review it or add the indexes it needs.

The assistant works on ER diagrams too. When an ER diagram is open, it thinks like a senior data architect: it designs schemas that last, normalised where it matters, named consistently, with the keys, constraints and indexes a production database needs. Setting it up, choosing the model, the change card and undo work the same as for a process. This page covers what's different.

Press ⌘ I (Ctrl I on Windows and Linux) to open it.

Draft a schema

On an empty ER diagram, the assistant offers domains to start from: Online store, Team workspace, Blog with comments, Appointment booking, Invoicing, Learning platform, Help desk tickets and Inventory across warehouses. Each one fills in a request to design the schema for it, such as "Design the database schema for online store." Edit it to fit your system, then send it.

Or describe the data in your own words. A good request says:

  • What the system keeps track of. The things to store, as you call them: "members, the classes they book, and the trainers who run them".
  • How the main things relate. "A member can book many classes, and a class has one trainer."
  • The rules only you know. What must be unique, what's required, what a status can be: "a member can't book the same class twice".
  • Which database it runs on, if it matters: "PostgreSQL". You can also set Database in Properties, and the assistant writes types for it.

For example:

Design the schema for our gym. Members book classes, each class has one trainer
and a room, and a member can't book the same class twice. Members pay a monthly
plan. Keep the history of plan changes. We use PostgreSQL.

For a well-known domain, such as an online store or a blog, or when you've named the tables, the assistant drafts straight away. For your own system, when you haven't said what it holds, it may first ask up to three short questions, each with the answer it would assume. To skip them, say "draft it now and list your assumptions".

How it designs

The assistant follows the same modeling style the schema code reference describes:

  • one schema per diagram, at one level of detail: about 3 to 25 tables;
  • table names as plural nouns and columns in lower case with underscores, such as order_items and customer_id, unless you give your own names;
  • a primary key on every table, and a foreign key named after what it points at, with the same type;
  • a junction table with a composite key for every many-to-many relationship, with the columns that belong to the pair, such as a role or a date;
  • an enum for a short, fixed list of states, and a table when the list changes or carries data;
  • not null, unique and defaults where the data needs them, money as decimal, never float, and created_at with a default of now();
  • the values that mattered at the time copied onto the row, such as an order line's unit price;
  • indexes on columns that are searched or joined often, and groups once there are more than about eight tables.

When it drafts, it can look up reference schemas for an online store, a multi-tenant SaaS, booking and scheduling, invoicing and billing, content and publishing, and history and audit, and adapts them to what you named. It doesn't pad a draft with tables you didn't ask for.

Change a schema

Point at what should change and say how:

  • "Add a categories table, with products in several categories."
  • "Make email unique on customers."
  • "Orders can have several shipments."
  • "Add soft delete to posts."

For small changes the assistant edits only what you asked about, plus what the change needs to stay correct, such as a junction table's keys or a foreign key's type. The rest keeps its ids and your comments stay on their elements. To have most of a schema redone, say so.

To point at particular elements, select them on the canvas before you send, or type @ and pick them from the list: each table followed by its columns, then enums and groups.

Use a command

Type / at the start of the message box to pick a command. Each one fills in a request for you to read over and send.

CommandWhat it asks for
/reviewReview the schema: missing keys and constraints, relationships that should be junction tables, naming and types, and fix what's plainly wrong
/fixFix the issues the checks found
/explainExplain in plain words, for a new team member: what each table holds and how they relate
/indexesAdd the indexes the schema needs for the queries it will obviously serve, and say why each helps
/draftDesign a schema you describe

On a diagram that already has tables, the starting points above the message box are Review this schema, a fix for the issues the checks found, Explain it, and Suggest indexes when the schema has no indexes yet, apart from keys.

What it does with your diagram

  • Drafting or redoing most of it: it writes the whole schema as schema code and replaces the diagram with it.
  • Smaller changes: it applies a batch of small edits to tables, columns, relationships, enums, groups and indexes. If one edit in a batch fails, none apply.
  • Checking its work: after every change it gets the checks back, and fixes errors and real problems before it finishes.

The change card lists what was added, changed and removed, such as a column that's now required or a table that was renamed. It ends with a short summary of what it modeled or changed, what it assumed, and one or two things you might add next.

Use your own AI app

A connected AI app can work on ER diagrams through the same tools:

  • Create one. Ask for it by name: "Create an ER diagram called Online store." create_diagram takes a kind, and erd makes an ER diagram. Without it, the AI creates a BPMN process.
  • Find one. list_diagrams says each diagram's kind, so the AI knows which diagrams are ER diagrams.
  • Read and write it. get_diagram returns the schema code with every element's id, write_diagram takes schema code, and edit_diagram takes edits to tables, columns, relationships, enums, groups and indexes. Tables can be named by id or name, and columns by id or as table.column.
  • Look things up. lookup_guidance has topics for ER diagrams: schema-code for the syntax, schema-style for the modeling style, and the reference schemas store-schema, saas-schema, booking-schema, billing-schema, content-schema and history-schema. The AI is told to look up the syntax before its first write. See Guidance topics for every topic, word for word.

The diagram card in the chat, live updates in the app and the version history work as they do for a process. See Tools for every tool and edit, with its parameters.

On this page