Repository navigation
feat(studio): dump a database to the filesystem from the connection context menu - #255
Conversation
…ontext menu Adds a "Dump to File" entry to the connection context menu, enabled only while the connection is live. The save target follows the engine: a .sql file for Postgres, MySQL and libsql, a .sqlite file for SQLite, and a folder for DuckDB, whose EXPORT DATABASE writes schema and Parquet side by side. The backend command already existed but its output was not re-importable. The Postgres, MySQL and libsql dumps wrote bare INSERTs with no DDL, and the Postgres value formatter turned timestamps, uuid, jsonb, arrays and bytea into NULL. Each dump now emits DDL first, then data, then foreign keys, so rows load before any constraint is enforced: - Postgres resolves column types through format_type, since information_schema reports "ARRAY" and "USER-DEFINED"; emits CREATE TYPE for the enums the dumped columns use, and setval for sequences. - MySQL uses SHOW CREATE TABLE and brackets the data with FOREIGN_KEY_CHECKS toggles. - libsql takes its DDL from sqlite_master and loads inside a transaction. Values are formatted binary-safely and writes are buffered. Round-trip tests for Postgres and MySQL dump, drop, restore, compare every value, and then assert that foreign keys and sequences still work.
handleRestoreDatabase opens a file picker, asks for confirmation and reads the selected file, but the capability set granted none of those: only dialog:allow-save and fs:allow-write-text-file were present, so every one of the three calls was rejected at runtime. Adds dialog:allow-ask and fs:allow-read-text-file; dialog:allow-open arrived with the dump feature in the previous commit.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Sorry @remcostoeten, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 4 days and 16 hours by commenting @sourcery-ai review. Upgrade to get a review now.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThe PR adds self-contained PostgreSQL, SQLite, and MySQL dump generation with restore tests. It adds a desktop connection action that selects an output path, invokes the dump command, and reports the result. ChangesDatabase dump export
Estimated code review effort: 4 (Complex) | ~45 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant ConnectionSwitcher
participant DatabaseSidebar
participant useConnectionActions
participant TauriDialog
participant commands.dumpDatabase
ConnectionSwitcher->>DatabaseSidebar: select Dump to File
DatabaseSidebar->>useConnectionActions: handleDumpConnection(connectionId)
useConnectionActions->>TauriDialog: select output path
TauriDialog-->>useConnectionActions: selected path
useConnectionActions->>commands.dumpDatabase: dump connection to path
commands.dumpDatabase-->>useConnectionActions: dump result
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Reviewer's GuideAdds a desktop-only, live-connection “Dump to File” workflow with engine-specific output targets and rebuilds PostgreSQL, MySQL, and libSQL exports as buffered, re-importable dumps containing schema, data, and correctly ordered constraints. The change also fixes Tauri permissions and adds round-trip and formatting coverage. Sequence diagram for dumping a live database to a filesequenceDiagram
actor User
participant Sidebar
participant Actions as useConnectionActions
participant Dialog as TauriDialog
participant Backend as dumpDatabase
participant File as DumpFile
User->>Sidebar: Select Dump to File
Sidebar->>Actions: handleDumpConnection(connectionId)
Actions->>Dialog: save or open
Dialog-->>Actions: outputPath
Actions->>Backend: dumpDatabase(connectionId, outputPath)
Backend->>File: write DDL, data, constraints
File-->>Backend: DumpResult
Backend-->>Actions: DumpResult
Actions-->>User: Dump complete toast
Flow diagram for re-importable SQL dump generationflowchart TD
Start["Start dump"] --> Schema["Read and resolve schema"]
Schema --> DDL["Write DDL"]
DDL --> Data["Write buffered INSERT data"]
Data --> Constraints["Write foreign keys and sequence resets"]
Constraints --> Flush["Flush output"]
Flush --> Result["Return DumpResult"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Adds a Dump to File entry to the connection context menu, enabled only while the connection is live, and fixes the dumps so the output can actually be re-imported.
What was broken
The
dump_databasebackend command already existed but was surfaced only as "Backup". Its output was not re-importable: the Postgres, MySQL and libsql dumps wrote bare INSERTs with no DDL, and the Postgres value formatter turned timestamps, uuid, jsonb, arrays and bytea into NULL.What changed
Each dump now emits DDL first, then data, then foreign keys, so rows load before any constraint is enforced.
format_type—information_schemareports "ARRAY" and "USER-DEFINED" — emitsCREATE TYPEfor the enums the dumped columns use, andsetvalfor sequences.SHOW CREATE TABLEand brackets the data withFOREIGN_KEY_CHECKStoggles.sqlite_masterand loads inside a transaction.The save target follows the engine:
.sqlfor Postgres/MySQL/libsql,.sqlitefor SQLite, and a folder for DuckDB, whoseEXPORT DATABASEwrites schema and Parquet side by side. SQLite and DuckDB were already correct and are untouched.Capability fixes
Two runtime gaps found by reading the capability set, both invisible to the test suite because it never goes through the UI:
open({ directory: true }), but onlydialog:allow-savewas granted — the call would have been rejected.handleRestoreDatabasecallsopen,askandreadTextFile, and none of the three were permitted. Restore was broken at runtime. Addsdialog:allow-askandfs:allow-read-text-file.Verification
cargo test --lib291 passed;DORA_LIVE_DB_TESTS=1live suite 10/10; studio typecheck clean; vitest 1117 passed; oxfmt/oxlint clean. New round-trip tests for Postgres and MySQL dump, drop, restore, compare every value, then assert foreign keys and sequences still work. Dump and Restore were also exercised by hand in the running app.Summary by Sourcery
Enable database dumps from the desktop connection menu and produce reliable, re-importable exports across supported engines.
New Features:
Bug Fixes:
Enhancements:
Tests:
Summary by CodeRabbit
New Features
Bug Fixes