fix(sql-editor): bind Backup restore to migrated connection; stop corrupting snapshots - #260
Merged
Merged
Conversation
…ing snapshots Restore from Compare Data Backup was executing reverse DML on the current Compare Destination, so switching Destination (or restoring from History while another credential was selected) could undo onto the wrong database. History also capped oversized snapshot JSON by appending a truncation marker, which made JSON.parse fail while Restore was still offered — silently destroying the durable undo safety net after partial migrates. Record connectionId in the snapshot, always restore against that credential, omit oversized/invalid snapshots instead of truncating them, and surface when History could not store the backup. Co-authored-by: huy.phan9 <huyplb@users.noreply.github.com>
huyplb
approved these changes
Aug 16, 2026
Contributor
Author
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_c8cc2fd6-f455-4cf6-8e51-68779d42847a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and impact
Two critical defects in Compare Data Backup / Restore (SQL Editor side-by-side migrate):
dest.connectionId). After a partial migrate to credential B, switching Destination to C (3+ credentials) or opening History while C is selected could reverse DML onto C.snapshot_jsonat 1MB by appending\n… (truncated), which is invalid JSON. Save still succeeded, History still offered Restore, andJSON.parsealways failed — so the durable undo safety net after a partial migrate was silently ruined (especially after reload).Root cause
cap()was shared for free-text scripts and machine-parsed snapshot JSON; truncation markers are fine for scripts, fatal for JSON.Fix
connectionIdin the Backup snapshot; Restore always targets that credential (refuse if missing / credential deleted). Legacy snapshots withoutconnectionIdonly restore when the current Destination still matches the recorded target host/database.cap()with omit-if-too-large / reject-if-non-JSON; returnsnapshotStoredfrom/data-migrations/startand warn when History could not keep the backup. Hide Restore for unusable History snapshots.Validation
npx vitest runondataMigratePlans.test.ts+data-migrate-history.module.test.ts— 16 passedcd apps/web && npx tsc --noEmit— cleanNote
High Risk
Changes DML execution targets for Restore and how backup snapshots are persisted—wrong-connection restore was a data-corruption class bug; fixes are correctness-critical for partial migrate undo.
Overview
Fixes Compare Data Backup / Restore so undo DML runs on the database that was actually migrated, and History no longer stores broken snapshot JSON that still offered Restore.
Restore targeting — Backup snapshots now include the destination
connectionId. Restore (toast, in-session backup, and History) executes reverse DML on that credential instead of whatever Compare Destination is selected later. Migrate-time connection id is captured for toast actions; missing or deleted credentials block restore with a clear message. Older snapshots withoutconnectionIdonly restore when the current Destination still matches recorded target host/database.Snapshot storage — Replaces truncating
snapshot_jsonwith a truncation marker (invalid JSON) withstoreableSnapshotJson: store only intact parseable JSON under the 1MB cap, or omit and reportsnapshotStored: falsefrom/data-migrations/start. Scripts still truncate for display viacapScript. UI warns when backup is session-only; History hides Restore for unusable snapshots and shows an error for legacy truncated entries.Tests cover
storeableSnapshotJson, snapshotconnectionId, andisUsableDataMigrateSnapshot.Reviewed by Cursor Bugbot for commit e48b203. Bugbot is set up for automated code reviews on this repo. Configure here.