Databases and ER schemas
A database is a container whose technology is a database. Inside it, instead of components, there is its schema: tables with their columns and keys, drawn as an ER diagram.
The technologies that count as a database are PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, ClickHouse, MongoDB, Redis, Cassandra, DynamoDB, Elasticsearch, Neo4j, CouchDB and InfluxDB.
Add the database
On the Containers level of a system:
- PostgreSQL and Redis have presets: press Add block and choose one.
- For any other database, add an Empty block, open its panel and choose the database in Technology.
As with brokers, the first technology decides. Connect the services that use the database to it, and label the line with what they do, for example "reads and writes orders".
Open the schema
Click the magnifier on the database's block. The level that opens is called Schema. It is empty at first.
Add tables
Press Add block. The menu here is about tables:
| Row | What it does |
|---|---|
| Empty table | Adds a table with one column, id, as the primary key. |
| Schema editor | Opens the editor for all tables at once (see below). |
| users | Adds a users table: id, email, created_at. |
| orders | Adds an orders table: id, user_id, total, created_at. |
A double click on the canvas does not add tables here. Each table is a card listing its columns, with a key mark on the primary key.
The schema editor
Click a table, or choose Schema editor in the menu. The editor is titled Schema · name of the database and says which types it suggests, for example PostgreSQL types. The type list follows the database: PostgreSQL, MySQL, SQL Server, Oracle, SQLite and ClickHouse have their own; MongoDB and other document stores get document types; the rest get generic types.
On the left is the list of tables with the number of columns in each. Add table adds one. With eight tables or more a search field (Find a table) appears above the list.
On the right is the selected table:
- Its name, at the top. The button next to it, Table details, opens the table's Description, tags and group; the bin deletes the table.
- Its columns, one row each:
- the key button, Primary key;
- Column, the name;
- Type, picked from the list for this database, grouped into numbers, text, date and time, binary and other. A type that is not in the list is kept as typed;
- NN, not null;
- References, the foreign key: the column of another table (or this one) this column points at. The list shows primary and unique columns first. A key column without its own type takes the type of what it points at;
- More settings: Unique, Auto-increment, Default (a value or an expression such as
now()), Comment, and buttons to move the column up or down; - the bin, Delete column.
- Add column under the list adds a row.
- Referenced by at the bottom lists the tables that point at this one; click one to go to it.
The editor does not save while something is wrong: a table without a name, two tables or two columns with the same name, a column without a type. The problem is named in the editor and the table is marked in red in the list. Press Save to write all tables at once.
Foreign keys on the canvas
There are two ways to make a foreign key:
- In the schema editor, choose the target in the column's References.
- On the canvas, drag from the dot on the right edge of one table to the other table. The schema editor opens at the first table; choose the column in References and save.
The key is drawn from the row of the key column to the row of the column it references, and the line is labelled with both, for example user_id → id. Click the line to open the schema editor at that table again.
Tables can also be described in documentation: see Project documentation.