Repository navigation
restore: rename the database when CREATE DATABASE follows header comments - #560
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
…ents Signed-off-by: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com>
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.
restore --database FOO:BARis documented to restoreFOOintoBARand make sureBARexists. On the tool's own dump files it fails every time:The dump header puts comment lines right before
CREATE DATABASE(--\n-- Current Database: \shop`\n--).Restorecollects them into the same statement, socreateRegex, which is anchored with^, never matches, andCREATE DATABASEkeeps the old name. TheUSEline that follows has no comments, so it is rewritten toshop2, and MySQL is told to use a database that was never created. Ifshop` was missing, it also gets created, empty.--comment lines are now skipped between statements, as the mysql client does. Lines inside a statement are untouched.Testing: added
TestRestoreRenamesDatabaseAfterHeaderCommentsinpkg/database. It records the statementsRestoreexecutes through a small test driver. On main it gets the header comments plusCREATE DATABASE ... `shop`, and with the changeCREATE DATABASE ... `shop2`andUSE `shop2`.go test ./...passes. Against MySQL 8.4 in Docker, I dumped a database and restored it with--database shop:shop_fix: main fails with the error above, and the change restores all rows. A plain restore without--databasegives the sameCHECKSUM TABLEvalues as before the dump.