The second file contains a SHA-256 checksum of the SQL backup.

This allows the application to detect whether the backup file has changed or become corrupted.

2. Verify Backup button

The Import/Export window now includes Verify Backup….

Select an exported SQL file, and the application calculates its checksum and compares it with the accompanying checksum file.

3. Automatic verification before import

When importing an SQL file, WorkbenchReplacement checks for an accompanying .sha256 file.

If one exists, its checksum must match before SQL execution begins.

Third-party SQL files without checksum files can still be imported.

4. Large-file handling

Checksum calculation reads files in 1 MB blocks rather than loading the entire file into memory.

This reduces memory usage when verifying large backups.
This commit is contained in:
Mark Gregory
2026-10-16 22:00:32 +01:00
parent d75515ffbc
commit 5948387b4e
5 changed files with 97 additions and 2 deletions
+15
View File
@@ -0,0 +1,15 @@
# Phase 4 — SQL dump importer
- Adds parsing for MySQL `DELIMITER` directives, including stored procedure/function/trigger bodies.
- Preserves MySQL executable comments (`/*! ... */`) and block comments.
- Handles quotes, escaped quotes, and semicolons inside strings.
- Updates the import interface explanation.
- Does not require mysql, mysqldump or Homebrew.
## Important limitations
This is not a production-ready backup/restore solution. The importer still reads the entire SQL file into memory, executes each statement through the existing connection runner, and does not roll back statements already executed after an error or cancellation. Server privileges and server-specific SQL syntax may prevent imports. Validate against a disposable database before using with valuable data. The macOS Xcode build has not been run in this environment.
## Build
`xcodebuild -project WorkbenchReplacement.xcodeproj -scheme WorkbenchReplacement -configuration Debug -destination 'platform=macOS,arch=arm64' -derivedDataPath ./build build`
+5
View File
@@ -0,0 +1,5 @@
# Phase 5 — Built-in MySQL routine and trigger export
Adds opt-in export of stored procedures, functions and triggers via SHOW CREATE, using DELIMITER directives compatible with the Phase 4 importer. Export requires relevant MySQL privileges. The export includes these objects only when table structure export is enabled. The existing schema/table/view selection is unchanged.
Limitations: not tested in Xcode or against a live MySQL instance; no consistent snapshot, deterministic pagination, or complete backup verification. Do not use as the only production backup. The importer executes individual statements and does not provide rollback on failure.
+9
View File
@@ -0,0 +1,9 @@
# Phase 6 — SQL backup integrity
Adds streaming SHA-256 checksum creation for successfully exported SQL files, a **Verify Backup…** button, and automatic checksum validation before importing when a `.sha256` sidecar is present.
The `.sha256` file must be kept alongside the `.sql` file with the same basename. The verifier reads the SQL file in 1 MiB blocks rather than loading the file into memory. Third-party SQL imports without a sidecar are allowed.
**Not yet implemented:** transaction-consistent snapshots, reliable ordering of table rows across pages, import streaming, rollback on partial restore, cryptographic signing/authenticity, or end-to-end restoration tests. A matching SHA-256 proves file integrity relative to the stored checksum, not database completeness or correctness. Do not rely on this as a production backup system.
This Linux environment cannot run Xcode; build and live-MySQL testing are required on macOS.
+10
View File
@@ -0,0 +1,10 @@
# Phase 7 — Safer table data exports
- Requires a non-null unique index (prefers PRIMARY) for each table being exported with data.
- Adds explicit ORDER BY to every 250-row data page, preventing arbitrary server ordering.
- Checks row count before and after export, and compares it to rows written. On mismatch, aborts and deletes the temporary SQL file.
- Keeps Phase 6 SHA-256 sidecar verification and all existing UI features.
## Limitations
This is **not a consistent snapshot**. Concurrent updates can still change row contents without changing counts, and inserts/deletes can cancel each other out. OFFSET pagination is still used; a future phase must introduce a dedicated, isolated snapshot connection and keyset paging. Tables lacking a non-null unique index cannot be data-exported in this version. No Xcode or live server test was performed. Do not rely on these exports as sole production backups.