# 7. The schema designer

*Tabellum for mobile, chapter 7. On the web: https://tabellum.dudko.dev/manual/mobile/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 tap **Apply**, and then you see every statement first. A design is a file in `designs/`.

## 7.1 Starting a design

Open the menu and tap **+** next to **DESIGNS**.

![A new design](https://tabellum.dudko.dev/manual/mobile/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 on the canvas](https://tabellum.dudko.dev/manual/mobile/img/design.jpg)

*A design on the canvas*

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) Add an object.

- (1) is the connection **Apply** runs on.
- (2) and the round **+** button (5) add 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.
- The arrows just before (3) undo and redo 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.

A tap on a table opens its inspector in a sheet from the bottom: name, comment, columns with their types and defaults, keys, foreign keys, checks and indexes, and the SQL for that object. Drag the sheet down to close it; its expand button opens the object full-screen.

![The inspector of the selected table](https://tabellum.dudko.dev/manual/mobile/img/design-sheet.jpg)

*The inspector of the selected table*

## 7.3 Reviewing and applying

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

Tap **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/mobile/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 undo 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

The expand button in the inspector opens an object in its own tab, with its definition and a preview: sample rows, the query plan, or the SQL that would run.

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

*A table full-screen*

Marked on the screenshot: (1) Back to the canvas; (2) The form, or its preview.

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

*An enum type and its values*

**Canvas** (1) goes back to the design. **Definition** and **Preview** (2) switch between the form and the preview.

## 7.6 Creating a database

![A design that creates its database](https://tabellum.dudko.dev/manual/mobile/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.
