# 7. The schema designer

*Tabellum for desktop, chapter 7. On the web: https://tabellum.dudko.dev/manual/desktop/the-schema-designer*

The designer is a canvas for changing a schema the way you would draw it: add tables, drag foreign keys between columns, edit types and constraints. Nothing touches the database until you click **Apply**, and then you see every statement first. A design is a file in `designs/`.

## 7.1 Starting a design

Click **+** next to **DESIGNS** in the sidebar.

![A new design](https://tabellum.dudko.dev/manual/desktop/img/new-design.jpg)

*A new design*

Marked on the screenshot: (1) Where the design starts from; (2) Create a new database instead.

Under **Start from** (1), choose:

- **Connection** — the database’s schemas as they are now. Applied back to the same database, nothing changes until you edit something.
- **Snapshot** — a saved snapshot, to build on it or bring a database back to it.
- **Design** — a copy of another design.
- **Empty** — a blank schema.

**Create a new database** (2) makes the design create its database first; you choose its name, the server it is created on and its options.

## 7.2 The canvas

![A design: the canvas, and the inspector for the selected table](https://tabellum.dudko.dev/manual/desktop/img/design.jpg)

*A design: the canvas, and the inspector for the selected table*

Marked on the screenshot: (1) The connection Apply runs on; (2) Add a table, view, function…; (3) Reload the design from the database; (4) Apply the changes; (5) The selected object.

- (1) is the connection **Apply** runs on.
- (2) adds a table, view, materialized view, function, procedure, sequence or enum type — what the database supports.
- Drag a table to move it. Drag from a column’s port (the ring at its edge) onto another table’s column to create a foreign key. Double-click empty canvas to add a table there, or a table to open it full-screen.
- The inspector (5) edits what you selected: name, comment, columns with their types and defaults, keys, foreign keys, checks and indexes, and shows the SQL for that object.
- `Cmd+Z` undoes and `Cmd+Shift+Z` redoes any change, including moves.
- **Auto-layout** arranges the canvas; **Columns** shows or hides the columns.

Tables marked **new** or **changed** differ from the database; a red dashed table is one the database has and the design does not, which **Apply** would drop.

## 7.3 Reviewing and applying

The **Changes** drawer under the canvas is always up to date: how many statements **Apply** would run, what it would drop, any warnings, and the statements themselves.

![The Changes drawer, open](https://tabellum.dudko.dev/manual/desktop/img/design-changes.jpg)

*The Changes drawer, open*

Click **Apply** (4) in the canvas picture. The statements open in the approval dialog and run in one transaction where the database allows it.

![Applying a design](https://tabellum.dudko.dev/manual/desktop/img/design-apply.jpg)

*Applying a design*

The code button next to **Apply** opens the same script in a query tab instead, to run it yourself or keep it.

## 7.4 When the database has changed

If someone changed the database after you made the design — a migration, a new table — **Apply** would undo their change. Two buttons bring the design up to date:

- **Reload from the database** (3) reads the database again, lists what your design would lose, and replaces the design with the database’s schema. Table positions are kept, and `Cmd+Z` brings your version back.
- **Take from the database**, in the inspector of a table marked **changed**, replaces that one table with the database’s version and keeps the rest of your design.

## 7.5 Full-screen editors

Double-click an object (or use the arrow button in the inspector) to open it in its own tab. On the left is its definition, on the right a preview: sample rows, the query plan, or the SQL that would run.

![A table full-screen: definition and preview](https://tabellum.dudko.dev/manual/desktop/img/object-table.jpg)

*A table full-screen: definition and preview*

Marked on the screenshot: (1) Back to the canvas; (2) Preview rows, plan or SQL.

![A view](https://tabellum.dudko.dev/manual/desktop/img/object-view.jpg)

*A view*

![An enum type and its values](https://tabellum.dudko.dev/manual/desktop/img/object-enum.jpg)

*An enum type and its values*

**Canvas** (1) goes back to the design. **Rows**, **Plan** and **SQL** (2) switch the preview.

## 7.6 Creating a database

![A design that creates its database](https://tabellum.dudko.dev/manual/desktop/img/new-database.jpg)

*A design that creates its database*

On PostgreSQL you choose the owner, template, encoding and collation; on MySQL the character set and collation; on SQL Server the owner and collation. Without a server, the new database is an SQLite file in the workspace.
