The assistant for ER diagrams

Ask the assistant to design a database schema for you, at the level of detail you want.

The assistant works on ER diagrams too. Press ⌘ I (Ctrl I on Windows and Linux) to open it.

On an ER diagram, 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 drafting a new schema.

To work on one that has tables, see Change a schema. To work from Claude, ChatGPT, Gemini or another AI app, see Use your own AI app.

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, as you call it: "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, such as what must be unique or required, or 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, the assistant drafts straight away. It does the same when you've named the tables.

For your own system, when you haven't said what it holds, it may first ask up to three short questions. Each comes 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 picked from your request: about 6 to 10 tables with their keys and defining columns for an overview, up to 25 tables with every column for the detail;
  • 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 and adapt them to what you named. There are reference schemas for an online store, a multi-tenant SaaS, booking and scheduling, invoicing and billing, content and publishing, and history and audit. It doesn't pad a draft with tables you didn't ask for.

Say how much detail you want

A long description isn't a request to put every table and column on one diagram. Say which level you want, and the assistant keeps to it:

  • An overview ("an overview", "the main entities", "for the architecture review", "for a slide") shows the entities, how they relate, their keys and the few columns that define each, in about 6 to 10 tables.
  • The detail ("in detail", "the full schema", "every field", "so we can build it") shows every table, column, constraint, enum and index your description implies, up to about 25 tables.

When you don't say and the description is long, it drafts the overview. The tables your work produces, such as trips, appointments and payments, stay on the overview, and a catalogue such as suppliers goes before them.

A log, history or line table that doesn't fit folds into a note on the table that holds it, such as Reminders sent and cancellations are logged per appointment on appointments. Its answer says what it folded.

Nothing you stated is dropped in silence. To go deeper, name the part: "Add the reminders and cancellations tables" draws them. For how levels of detail work in every kind, see Level of detail.

On this page