Files
helder/docs/guide/schema.md
T

133 lines
8.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Schema
The Schema view is a full-screen diagram of a Laravel app's database: every table as a card, every foreign key as a line. Hover a table to trace what it points at and what points at it, click it to read its columns, and hand a table to Claude. Open it with `Cmd+D`.
[Guide index](index.md) · Related: [Git](git.md), [Title bar](title-bar.md), [Claude Code](claude-code.md), [Notifications](notifications.md)
## At a glance
```text
+----------------------------------------------------------------------------+
| (1) [ schema ] = mysql . shop dumped 14:32 . 16 tables . 23 relations |
| app/Console/.../HelderSchemaCommand.php [>_ Re-run] [x] |
|----------------------------------------------------------------------------|
| (2) Q Find a table | (3) | (5) users x |
| [ TABLES ] 16 | +-----------------+ | [ COLUMNS ] 8 |
| |users 1,284 | | posts 312 | +-------+ | id bigint |
| posts 312 | | PK id bigint | | users | | PRIMARY . NOT.. |
| comments 9,812 | | FK user_id ----+--->| PK id | | [ HAS MANY ] |
| | +-----------------+ +-------+ | <- posts via .. |
| | (4) drag to pan ... [- 80% + Fit] | [Pass on][Copy] |
|----------------------------------------------------------------------------|
| (6) [ console ] artisan v |
| $ php artisan helder:schema |
| Wrote database/helder/schema.json (18.4 KB) |
+----------------------------------------------------------------------------+
```
1. **Top bar**: the database, when the dump was made, the command path, the Run button and Close.
2. **Table list**: a search field and every table with its row count.
3. **Canvas**: the table cards and the relationship lines.
4. **Hint and zoom control**: how to move around, and zoom out, the zoom level, zoom in and Fit.
5. **Detail panel**: the selected table's columns and relations, while a table is selected.
6. **Console**: the output of `php artisan helder:schema`.
## Features
### When the view exists
- Only in a Laravel app: a project with an `artisan` file in its root. Anywhere else there is no **Schema** button and `Cmd+D` does nothing.
- The diagram comes from `database/helder/schema.json`. The app's own Artisan command `app/Console/Commands/HelderSchemaCommand.php` writes that file. See [the schema.json contract](../schema.md).
### Open and close the view
- `Cmd+D`, the **Schema** toggle in the [Title bar](title-bar.md), or View > Show Schema opens it. The toggle's dot is amber while the view is open.
- The view covers the whole window. The columns stay as they were under it, and terminals keep running.
- From [Search](search.md) or the [Diff](file-view-diff.md), `Cmd+D` closes it and opens the view. If the view is already open under Search, `Cmd+D` only closes Search.
- Close it with `Cmd+D`, `Esc`, or the **Close** button. The keyboard goes back to the column that had it.
- The Git view and the Schema view never show together: opening one closes the other.
- The view is not remembered: a project always opens with it closed.
### No command yet
A Laravel app without `HelderSchemaCommand.php` opens the view on `[ NO COMMAND YET ]`:
```text
+--------------------------------------------------+
| [ NO COMMAND YET ] |
| - Helder draws the schema from |
| database/helder/schema.json. The Artisan command|
| app/Console/Commands/HelderSchemaCommand.php |
| writes it, and this app does not have it yet. |
| [* Generate command] [Copy prompt] |
| +----------------------------------------------+ |
| | Build an Artisan command that dumps ... | |
| +----------------------------------------------+ |
+--------------------------------------------------+
```
- **Generate command** closes the view and puts a prompt in the Claude prompt. It does not send it: read it, then press `Return` yourself.
- **Copy prompt** copies the same prompt, for another agent or a ticket.
- The box below shows the whole prompt, so you know what Claude gets.
- When Claude writes the command and runs it in the terminal, the view switches to the diagram by itself.
### No dump yet
With the command but no `database/helder/schema.json`, the view shows `[ NO DUMP YET ]` and a **Run helder:schema** button. A dump that already exists loads as soon as the view opens.
### Run the command
- **Run helder:schema** (or **Re-run helder:schema** once there is a dump) runs `php artisan helder:schema` in the project folder. Helder uses Laravel Herd's `php` when it is installed, else the `php` on your `PATH`.
- While it runs, the button reads `Dumping…` and more clicks do nothing. A run stops after 120 seconds.
- The console shows each line as it arrives: errors in amber, the `Wrote …` and `DONE` lines in teal.
- When it succeeds, the diagram reloads and a [notification](notifications.md) reads `Schema dumped · 16 tables`.
- When it fails, the console stays open with the error.
- A `schema.json` that is not valid JSON shows its error in the console and the notification `Could not read the schema`.
### Table list
- Type in **Find a table** to filter the list. `Return` selects and centres the first match. `Esc` clears the search, while the search has the keyboard.
- The label reads `[ TABLES ] 16`, or `[ TABLES ] 3 of 16` while filtering.
- Hover a row to trace that table on the canvas. Click a row to select it and move it to the middle.
### Move around the canvas
- Drag the empty background, or scroll, to pan.
- `Cmd` + scroll, `Ctrl` + scroll, or pinch to zoom around the pointer, from 30% to 200%.
- The control at the bottom right: `−` and `+` zoom around the middle; **Fit** shows every table.
- The first dump fits itself to the window. After that, a new dump keeps your view.
### Arrange the tables
- Drag a card to move it. A press that hardly moves is a click.
- Helder remembers where you put the cards, per project. A new dump keeps them; new tables get a default place.
- The default places put tables that point at nothing on the left, and each other table one lane right of the deepest table it points at.
### Trace a relation
- Hover a table: its lines turn amber, related tables get a grey outline and the rest fade.
- Hover a foreign-key row (`FK`) to trace only that one relation.
- With a search and nothing hovered or selected, matching cards get an amber outline and the rest fade.
### Inspect a table
- Click a card to select it; the detail panel opens on the right. Click it again, or the empty canvas, to close it.
- **[ COLUMNS ]** lists every column with its type and flags, such as `FK → users.id · NULL`.
- **[ BELONGS TO ]** lists the tables this one points at; **[ HAS MANY ]** the tables that point at it. Hover a row to trace that table; click it to select it and move to it.
- **Pass on to Claude** closes the view and puts `@schema:<table>` in the Claude prompt.
- **Copy name** copies the table name.
### Console
- It opens on the first run, at the bottom, and keeps the last 400 lines.
- The chevron hides it until the next run.
### How the view stays up to date
You do not need to refresh by hand. Helder watches the project folder: when the command file appears or goes, or `database/helder/schema.json` changes, the view follows. `Cmd+R` checks again too.
## Keyboard
| Keys | Action |
|---|---|
| `Cmd+D` | Open or close the Schema view (Laravel apps); from Search or the Diff, close it and open the view |
| `Return` | In the table search: select and centre the first match |
| `Esc` | Deselect the table, then clear the search (while it has the keyboard), then close the view |
| `Cmd+G` | Switch to the Git view |
## Related
- [Git](git.md): the other full-screen view.
- [Title bar](title-bar.md): the **Schema** toggle.
- [Claude Code](claude-code.md): where the prompt and `@schema:<table>` land.
- [The schema.json contract](../schema.md): the file the command writes.
- [Keyboard shortcuts](keyboard-shortcuts.md): every shortcut in one list.