Skip to content

refactor(import): run a SQL file through the streaming restore - #654

Merged
EVWorth merged 1 commit into
mainfrom
fix/import-sql-streaming
Sep 12, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/import-sql-streaming

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Closes #367, #578 — and removes the second implementation of a thing the backup work had just built properly.

SQL import and restore were the same operation, twice

The import one read the whole file into the renderer, split it there, and sent back one statement per call — each on whichever pooled connection it landed on, so a USE or a session setting did not carry to the next, and the file was capped at what the WebView can hold. That is exactly what #359 and #358 were about on the restore side.

It now calls restore_database. The backend reads in chunks, splits in Rust (quotes, comments, DELIMITER), and runs on one connection with the foreign-key checks off and a transaction that is honest about its reach.

The dialog reads only the first 512 KB — enough to preview the file and name what it will drop — and says so when the scan did not reach the end, instead of reporting "3 statements detected" for a two-gigabyte dump.

The summary now distinguishes the two outcomes that matter: "stopped at statement 12, rolled back — the database is as it was" and "stopped at statement 12; what already ran stands, because MySQL commits before every CREATE, DROP or ALTER".

#367 was already built; the remaining half is rejected

The destructive-statement warning exists: the preview counts them up front and lists the first five. This PR extends it to say when only part of the file was scanned.

Not doing the "require typing import to confirm" half. That gesture belongs to actions with no other guard and no undo — deleting a GitHub repo. Here there are already two: the amber list naming the statements, and the production gate, which raises its own dialog on a production connection. A third, typed, on every import would be trained away within a week and would make the two that matter easier to click through.

#578 was already fixed

parseCSVLine keeps whether a field was quoted, and generateBatchInsert uses it: ,, becomes NULL and ,"", stays ''. That is mysqlimport's convention and the one the issue proposed. No option is exposed, deliberately — the issue's own framing was "a choice the file cannot express", and the file can now express it.

Also

A progress subscription that cannot attach no longer stops the work — it means the bar does not move, and refusing to run over that was the wrong trade. All three dialogs (backup, restore, import) go ahead without it.

2703 unit, 344 browser, clean.

SQL import and restore were the same operation with two implementations.
The import one read the whole file into the renderer, split it there and
sent back one statement per call — each on whichever pooled connection
it landed on, so a `USE` or a session setting did not carry, and the
file was capped at what the WebView could hold.

It now calls `restore_database`: the backend reads the file in chunks,
splits it in Rust and runs the statements on one connection, with the
foreign-key checks off and a transaction that is honest about its reach.
The dialog reads only the first 512 KB, to draw the preview and to name
what the file will drop — and says so when the scan did not reach the
end, rather than reporting "3 statements" for a two-gigabyte dump.

The summary now says whether what already ran survives: MySQL commits
before every CREATE, DROP and ALTER, so "stopped at statement 12" means
different things depending on what came before it.

A progress subscription that cannot attach no longer stops the work.
It meant the bar does not move, and refusing to run the import over that
was the wrong trade — all three dialogs now go ahead without it.
@EVWorth
EVWorth merged commit ec6fa1d into main Sep 12, 2026
12 checks passed
@EVWorth
EVWorth deleted the fix/import-sql-streaming branch September 12, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1][ux] Preview pane doesn't warn about destructive statements (DROP/TRUNCATE/DELETE)

1 participant