← All tutorials · Opsdeck

Tutorial 8 of 8

The Database desk

Intermediate 10 min

Draw an ER diagram from DDL, turn two schema versions into a checked migration with rollback, normalise a relation step by step, format and lint SQL, and query CSV or JSON tables, all in the browser.

1. Open the desk

Database desk is the last section in the sidebar (press 0). Its five tabs share one SQL dialect setting: Schema and diagram, Diff and migration, Normalisation, Formatter and linter and Query playground. Everything is computed in this browser from the text you paste. Opsdeck never connects to a database, so nothing here can change live data.

The fastest start is New from template → Database review: schema change and slow query. It fills every tab with invented sample data. Everything you type is saved in the deck, and Undo works as everywhere else.

2. Schema and diagram

Paste CREATE TABLE, CREATE INDEX and ALTER TABLE statements into Schema (DDL), use Open .sql file… or pick one of the Examples. The diagram updates as you type:

  • Layout: Layered (referenced tables on the left) or Force-directed (seeded). Layout seed gives the same picture every time.
  • Show column types can be switched off for a compact overview. Fit to width and Actual size change only the view.
  • SVG, PNG and Mermaid export or copy the diagram. Relationships (text alternative of the diagram) describes every line in words, and Tables counts keys, indexes and checks.
  • Notes from the parser lists skipped statements (views, triggers) and problems such as a foreign key to a missing table. Normalised DDL shows how Opsdeck read your schema.

3. Diff and migration

Put the old version in Current schema (DDL) and the new one in New schema (DDL). Start the new version from the current one copies it so that you can edit the copy, and Swap exchanges the two.

The result lists Changes per table, a migration script and a rollback script, each with Copy and Download .sql. Warnings are marked Destructive (data is lost or cut off) or Risky (fails if existing rows break a new rule). Both scripts are verified: Opsdeck applies them to the parsed schema and compares the result. If you renamed a column, add a line under Rename hints (optional), for example customers.name -> full_name. Without it the diff drops the column and adds a new one, and the data is lost.

4. Normalisation

Enter a Relation such as R(A, B, C, D) and the Functional dependencies (one per line), or open a Textbook examples case. You get the Candidate keys, the Normal form with every violation explained, the Attribute closures, the Minimal cover, a 3NF synthesis (Bernstein) and a BCNF decomposition, each checked for Lossless join and Dependency preserving.

Put your own split under Decomposition to test (optional) and read the Chase tableau of your decomposition: a row of only a-symbols proves the join is lossless. Under Find dependencies in sample rows you can paste CSV. The Dependency hypotheses from the sample are only suggestions: a sample can refute a dependency, but it cannot prove one.

5. Formatter and linter

Paste SQL, choose Keyword case and Indent width (spaces) and read the Formatted SQL. Replace the input with the formatted SQL writes it back. The lint list flags UPDATE and DELETE without WHERE, comma joins without a condition, SELECT * in views, = NULL and other patterns, each with the statement and line.

6. Query playground

Load Sample datasets or use Open CSV or JSON file… to create tables. Add table lets you paste data directly. Then write a SELECT query and press Run query or Ctrl+Enter. The playground supports inner, left and cross joins, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, aggregates and CASE. NULL follows SQL rules. How the query ran shows the row count after every step, and the result downloads as CSV.

7. Outside the app

Four tools on the Opsdeck host use the same engine: opsdeck-schema-diff, opsdeck-er-diagram, opsdeck-normalization-checker and opsdeck-sql-formatter. Each has a tool page, POST /api/v1/tools/<id>/calculate and an MCP tool. For the same input they give exactly the result the desk shows. The desk is stored under database in the deck file, as documented in /project.schema.json.

Ready to try it?

Launch Opsdeck →