DataWright
A database workbench for VS Code: PostgreSQL, SQLite and Google Cloud Firestore connections, a table viewer, a query runner, notebooks, and figures (charts, ERDs, query plans). A phone app follows. DataWright is TackRoom's sibling and shares its typefaces, surfaces, brass accent and icon grammar.
What works today
- Connections view in its own activity-bar container. Connections belong to the workspace: each folder or workspace has its own list, and ERD layouts are kept with them. The first time a workspace opens with this version, it gets a copy of the connections saved before (when they were shared by every workspace), with their passwords and diagrams; after that, adding or removing a connection changes only that workspace. Add a PostgreSQL server or a SQLite file, or open the built-in sample
shop database (customers, orders, order items, products, and a daily_revenue view). Postgres connections list their schemas, then tables and views; tables show their row counts (the planner's estimate on Postgres, marked ~); columns show their type, the primary-key rivet and foreign keys (→ customers).
- Table viewer: click a table to open it in the Results tab, a DataGrid with typed headers,
NULL spelled out and a row/time status bar.
- Query runner: open a
.sql file or New Query, and press Ctrl+Enter (Cmd+Enter on Mac) to run the selection, or the statement the cursor is in. The status bar shows which connection queries run on; click it to change. Statements that change every row ask first.
- Notebooks:
.dwnb files open as VS Code notebooks. SQL cells run on the notebook's connection, and results render as the same grid in the cell output. Pick a cell's dialect, SQL or PostgreSQL, from the language picker in the cell's corner; new notebooks on a Postgres connection start with PostgreSQL cells. .pgsql and .psql files open as PostgreSQL and run like .sql files.
- ERD: right-click a connection or schema and choose Show ERD, or run DataWright: Show ERD, to draw its tables and foreign keys. Drag a table to move it; it stays where you put it, per connection and schema, in this workspace. Every line is labelled 1 or N at each end and shows its kind (1:1, 1:N, N:N) in the middle: 1:1 when the foreign key column is unique, else 1:N. Link tables (a primary key made of foreign keys, like
order_items) get an N:N tag, and selecting one draws the many-to-many line between the tables it joins. Click a line to change its kind or which side of each table it attaches to; that only changes the drawing, and is saved with the layout. Click a table to highlight its relationships. The ERD tab reopens with the same diagram after VS Code restarts, and Show ERD from the Command Palette reopens the last one. Relations in the ERD's header (the datawright.erd.relations setting) picks where lines come from: Foreign keys (the database's constraints), Foreign keys + names (also guesses lines from column names, for databases without constraints such as Django models with db_constraint=False or managed = False: author_id refers to author, authors or a table ending in _author, the way user_id refers to Django's auth_user), or Names only. Guessed lines are dotted. Each table draws its primary key first, then its foreign keys ordered by how high the table they refer to sits, so lines coming into a table do not cross, then its other columns (datawright.erd.keysFirst turns this off; the database and design files keep their own column order). Auto Layout places every table again. The diagram does not need the connection open: with it closed, the ERD is drawn from the schema as last read, marked Offline, and nothing reconnects on its own. When the connection opens again, the diagram is read again. Connect & Refresh opens it on request.
- Saved ERDs: Save As… in the ERD's header (or DataWright: Save ERD As…) writes the diagram to a
.dwfig file in the workspace and opens it. A .dwfig names its connection by name, never by id or password, and holds the card positions, line choices, focus table and Relations choice, so it can be committed and shared. Opening one draws the diagram from that connection in your workspace. Changes edit the file: it shows unsaved changes, Ctrl+S saves it, undo works. If your workspace has no connection by that name, Choose Connection… points the file at one of yours. The format is in docs/design/FIGURES.md.
- ERD designs: draw a schema before it exists. DataWright: New ERD Design… creates a
.dwfig that holds its own tables under spec.model, so it needs no connection or database. Write columns as "id": "integer pk", "email": "text unique not null" or "customer_id": "integer not null -> customers" (or -> customers.id). Edit as Text opens the file beside the diagram, which redraws as you type, so you can iterate on the design with an agent editing the file. Mistakes, like a reference to a table that does not exist, are listed above the diagram and in the Problems panel, on the table or column they are about, for every .dwfig in the workspace whether or not its diagram is open, so an agent editing the file reads them too. In the text editor, a .dwfig is JSON checked against DataWright's schema, with completion and the column short form described on hover. Cards, lines and Relations work as in any ERD and are saved in the same file. SQL writes the design as CREATE TABLE statements in a new tab, ready to run when you build it. You can also build it on the canvas, starting empty: double-click the canvas to add a table, double-click a table to edit its name and columns (type, primary key, unique, not null, and the table each refers to), and drag the dot at a column's right edge onto another table to draw a reference (from the header's dot, a new customer_id-style column is added). Each change edits the file, so undo and save work, and renaming a table updates the references to it. To rework a schema that already exists, Save as Design… in the ERD tab copies its tables into a design file, keeping the cards and line choices where they were; the database is not changed.
- Compare and migrate: a design can name the database it is meant for (Compare… in its header; designs from Save as Design… already do). The diagram then marks new tables and columns in green and changed ones in amber (hover a column for what changed), lists what the database has that the design leaves out, and counts the differences. While the diagram is open, the Problems panel lists the same differences as information, on the tables and columns they are about. Migration SQL writes the statements that would bring the database in line with the design, in a transaction, in a new tab. Nothing runs until you run it, and statements that would drop data are commented out. A closed connection is compared as it was last read; Refresh reads it again.
- Export to SVG or PNG: Export… in any ERD's header saves the diagram as an SVG (for READMEs, wikis and docs,
, following the reader's light or dark theme) or a PNG (for chats and slides). Teammates without DataWright, or without the database, see the same diagram. Or export a .dwfig.svg: one file that is an image everywhere and the editable diagram in DataWright, its picture redrawn on every save. Or turn on datawright.export.svgOnSave and saving a .dwfig writes its .svg beside it, so a README's picture is never out of date.
Designing with an agent
Any coding agent that speaks MCP (OpenCode, Claude Code, Codex CLI, Gemini CLI, Cursor, Antigravity, GitHub Copilot and others) can design schemas with you in .dwfig files while you watch the diagram. Run DataWright: Connect Agents… and tick the agents that should use it: DataWright adds one datawright entry to each one's user settings (Cursor, Gemini CLI, Antigravity, OpenCode 1.x and 2.x, Codex CLI, and Claude Code through its own claude mcp command), leaving the rest of those files as they were, and unticking removes it. GitHub Copilot in VS Code 1.101 and later finds DataWright on its own. For any other agent, Copy MCP Config for Agents… copies what to paste into its MCP settings. The agent then starts datawright-mcp, which DataWright keeps at ~/.datawright/bin/ and points at the installed version on every start (turn that off with datawright.agents.enabled). It runs with VS Code's own runtime, so no Node install is needed.
- What the agent gets: a guide to DataWright's format and to designing a schema well (questions to ask, keys, normal form, relationships, types, changing a schema that has data), and tools to list, read, check, create and edit designs and to write a design as
CREATE TABLE. Edits go through the same code as the canvas, so a rename carries its references and card places, and a list of edits is applied all or none.
- What it cannot do: change a database. There is no tool that runs SQL. You run the migration DataWright writes.
- The agent's server works in the folder the agent starts it in, and only on
.dwfig files inside it. If your agent starts MCP servers somewhere else, set DATAWRIGHT_WORKSPACE to the project folder in its MCP settings.
- With the project open in a DataWright window (VS Code, Cursor or Antigravity), the agent also sees the workspace's connections by name and engine (never addresses or passwords), reads a connection's tables and columns (the catalog only, never rows), saves a schema as a design, compares a design with its database, and writes the migration SQL, which opens in a tab for you to read and run. A closed connection answers with its schema as last read; DataWright never opens a connection for an agent. When you have a design open, the agent's edits go into your editor, so you see them and can undo them; with unsaved changes of your own, they stay unsaved. Each window answers only agents working in its own folders, over a local socket only you can reach. Column statistics and sample rows are planned; see docs/design/AGENTS.md.
Cancelling a query
Cancel query in the Results tab, the stop button that replaces Run in the editor while a query runs, or DataWright: Cancel Query stops the run. In a notebook, use the cell's stop button or the notebook's Interrupt; cells still waiting do not start.
- No statement after the cancelled one starts, and the message says exactly what had already run: "Cancelled. Statement 1 of 3 had already run; the rest did not."
- PostgreSQL stops the statement on the server with Postgres's own cancel request (it carries the session's secret key, so no second sign-in). A cancelled statement changes nothing. Inside a transaction the transaction is left aborted, and the message says to run
ROLLBACK.
- SQLite stops between statements and between batches of rows. A single statement that runs long without returning rows (a big
UPDATE, CREATE INDEX) finishes first: the built-in SQLite cannot interrupt a statement that is executing.
- While a query runs in the Results tab, a second Run is refused rather than queued, so nothing starts later that you did not expect.
Your data changes only when you run something that changes it
- Read-only connections. The Add Connection screen asks whether a connection may change data, with Read-only chosen by default. A read-only Postgres connection starts its session with
default_transaction_read_only=on, so the server itself refuses every write, and RESET or DISCARD cannot lift it. A read-only SQLite connection refuses writes before running them and never writes the file. Switch with Make Read-Only / Allow Changes… on the connection (Allow Changes asks first).
- Run never guesses. Ctrl+Enter runs the selection, or the statement the cursor is in. On a blank line or past the end of the file it runs nothing, instead of the nearest statement.
- Confirmation.
datawright.query.confirmChanges asks before statements that change every row (UPDATE/DELETE with no top-level WHERE, TRUNCATE; the default), before every change (allChanges), or never (off). Statements that look like reads but change data count as changes: EXPLAIN ANALYZE of a write, SELECT … INTO, PRAGMAs that set something.
- No quiet reconnects. If a Postgres session drops, the server has rolled back any open transaction. The next run stops once to say so instead of reconnecting silently, so statements meant for that transaction are not committed one by one.
- SQLite files are written only after a run that changed them, atomically (a temporary file, then a rename), and never over another program's changes: a file changed on disk is reloaded when DataWright has nothing unsaved, and otherwise DataWright refuses to save and says so. Files in WAL mode, or with a
-wal or -journal file beside them, open read-only.
- DataWright's own queries (the Connections tree, opening a table, type lookups) only read. Notebooks keep fields DataWright does not know when they are saved.
Adding and editing connections
Add Connection… opens a tab with a card for each engine (PostgreSQL, SQLite, Firestore, and the sample database), each with its logo, and every setting that engine has. Test connection opens and closes it and says what it found (the server version, the number of tables); Save and connect keeps it and opens it. Edit Connection… on a connection opens the same tab with its settings filled in; saving closes the open connection, which reopens with the new settings, and keeps its diagrams.
- PostgreSQL: host, port, database, user and password, or a whole Connection URL (pasting a
postgres:// URL into Host fills in every field). Save password keeps it in VS Code's secret storage; turned off, it is asked for on the first connect of each VS Code session. SSL / TLS: off, verify the server (verify-full), verify the CA only, or encrypt without verifying (no-verify), with CA certificate, client certificate and key files. Advanced: schema search path, application name, connect timeout, statement timeout, and other -c name=value server settings. Everything is saved as one URL, without the password.
- SQLite: open a file, or New file… to create an empty database.
- Firestore: sign in with gcloud (Application Default Credentials), a service account key file, or use the local emulator (
host:port, no sign-in). Project id, and the database id, with List databases to pick from the project's.
- Every connection has a name (a default is suggested) and its access: Read-only or Read and write.
PostgreSQL
Add a server from Add Connection… (above). The password is kept in VS Code's secret storage, never in settings; a password typed into the URL is moved there too.
- Each connection keeps one session open, as psql does, so
SET, temporary tables and an open transaction carry from one run to the next.
- Reads go through a server-side cursor, so a large table never comes over the network past the row limit.
- Values show as Postgres sends them (timestamps keep their offset, numerics keep their scale), with type names as people write them:
timestamptz, varchar(64), text[].
- Errors show Postgres's own message, its hint, and which statement failed when several ran.
- A dropped connection is noticed; the next run reconnects.
The driver tests run against a real server when DATAWRIGHT_PG_URL is set, and are skipped otherwise:
DATAWRIGHT_PG_URL=postgres://user:password@localhost:5432/scratch npm test
Use a throwaway database: the tests create and drop the schemas dw_test and dw_billing.
SQLite
SQLite runs through sql.js (SQLite compiled to WebAssembly), so nothing native has to be installed. A file is read into memory, and a run that changes it writes it back.
Firestore
Add Connection… → Firestore connects to a Google Cloud Firestore database, signed in with your gcloud Application Default Credentials (run gcloud auth application-default login once; the form offers to run it in a terminal), a service account key file, or no sign-in for the local Firestore emulator. DataWright stores no secret: gcloud holds the credentials, and a key file stays where it is. The account needs Firestore access in the project, such as the Cloud Datastore User role (Viewer for reads only).
- Connections view: the root collections, with their subcollections under them. A collection's fields are guessed from 50 of its documents, with their Firestore types (
string, timestamp, map, reference…). __id__ is the document id. Reference fields show as foreign keys (→ teams), so Show ERD draws them, including references inside maps and arrays, which get a row of their own (items[].product → products, shipping.carrier → carriers).
- Subcollections are named by their pattern,
users/{id}/orders: one entry for the orders under every user. They are found by asking 5 documents of each collection, two levels down. Firestore cannot list subcollections any other way, so one that none of those documents has is not found. A subcollection's __parent__ links it to the collection its documents live under, and the ERD draws that line. Open on a subcollection reads its collection group (db.collectionGroup('orders'), with __path__ showing where each document lives), which also includes any other collection named orders.
- Listing and sampling read documents, which Firestore bills: about 5 reads per collection to find subcollections, and up to 50 per collection the tree expands or the ERD draws.
- Queries are Firestore's own calls, as written with the SDK, in
.firestore files, New Query on a Firestore connection, or notebook cells set to Firestore. Ctrl+Enter runs the statement under the cursor. A line break ends a statement unless the next line starts with ., so chains can be broken before each call. .get() is optional.
db.collection('users').where('plan', '==', 'pro').orderBy('createdAt', 'desc').limit(20)
db.collection('users/ada/orders').where('total', '>=', 50)
db.collectionGroup('orders').where(Filter.or(Filter.where('status', '==', 'paid'), Filter.where('total', '>', 100)))
db.collection('orders').aggregate({ revenue: AggregateField.sum('total'), n: AggregateField.count() })
db.collection('users').count()
db.doc('users/ada').get()
db.listCollections()
db.collection('users').add({ name: 'Lena', joined: FieldValue.serverTimestamp() })
db.doc('users/ada').update({ 'address.city': 'Izmir', visits: FieldValue.increment(1) })
db.doc('users/ada').set({ plan: 'free' }, { merge: true })
db.doc('users/ada').delete()
- Queries:
where (every operator, including in, not-in, array-contains-any, and Filter.or / Filter.and), orderBy, limit, limitToLast, offset, select, startAt, startAfter, endAt, endBefore, count, aggregate, and FieldPath.documentId(). Values: strings, numbers, booleans, null, arrays, objects, new Date('…'), Timestamp.fromMillis(…), new GeoPoint(lat, lng) and db.doc('path') references.
- Results: one row per document,
__id__ first (plus __path__ for collection groups), then every field seen. Maps and arrays show as JSON. A query asks Firestore for no more documents than datawright.query.rowLimit (plus one, to know there were more).
- Writes:
add (shows the new id, like INSERT … RETURNING), create, set (with { merge: true } or { mergeFields }), update and delete, with FieldValue.serverTimestamp(), increment, arrayUnion, arrayRemove and delete(). Each statement is its own commit. A read-only connection refuses writes before running anything. Every Firestore write names one document, so confirmChanges asks before them only when set to allChanges.
- Every statement is read before any runs, so a mistake in the third leaves the first two unrun. Errors are Firestore's own; one that needs an index includes Firestore's link to create it.
- Cancel stops between statements and abandons the request in flight. A write already sent may have been applied, and the message says so.
Develop
npm install
npm run build # bundles into dist/
npm test # unit tests (node --test)
npm run typecheck # extension and webviews
npm run package # datawright-<version>.vsix
CI (.github/workflows/build.yml) builds and tests every push and pull request; pushing a vX.Y.Z tag publishes to the VS Code Marketplace and Open VSX. See docs/RELEASING.md.
Press F5 in VS Code (Run Extension) to open a development window with an isolated profile.
| Code |
What |
src/extension.ts |
Activation: commands, views, notebook, status bar |
src/connections.ts |
Saved connection profiles and open drivers |
src/db/ |
The Driver interface, the PostgreSQL, SQLite and Firestore drivers, the sample database |
src/addPostgres.ts, src/addFirestore.ts |
The Add PostgreSQL and Add Firestore Connection flows |
src/core/ |
Pure code shared with the webviews: result types, formatting, SQL splitting, the Firestore query language and REST shapes, the .dwnb and .dwfig formats, icons, ERD layout |
src/views/ |
The Connections tree, the Results tab, the ERD tab and the .dwfig editor |
src/notebook/ |
.dwnb serializer and the SQL cell controller |
webview/ |
The Results and ERD tab scripts, the notebook renderer, and the grid they share |
media/vscode.css |
Maps the design system's surfaces onto the VS Code theme |
Design system
| What |
Where |
| Brand book: voice, colour, type, space, icons, motion, components |
docs/design/DESIGN_SYSTEM.md |
The .dwfig figure format (charts, stats, ERDs, plans) |
docs/design/FIGURES.md |
The .dwnb notebook format |
docs/design/NOTEBOOKS.md |
| VS Code, phone app and web |
docs/design/PLATFORMS.md |
| Component guidelines |
docs/design/components/ |
| Live previews (open in a browser) |
docs/design/previews/index.html |
| Tokens |
design/tokens.json, compiled to media/tokens.css |
Component styles (dw- classes) |
media/components.css |
| Icons |
media/icons/ (DataWright), media/tack/ (TackRoom's, unchanged), src/core/dwIcons.ts |
| Mark and app icon |
media/brand/, media/icon.png |
| |