Repository navigation
feat(mysql): restore mysqldumps with their indexes; scope index names to their table - #58
Merged
Merged
Conversation
… to their table
Inline KEY / INDEX / UNIQUE KEY in CREATE TABLE (previously dropped, or
reduced to an anonymous UNIQUE) become named CREATE [UNIQUE] INDEX
statements. MySQL index names are per table and SQLite's per database, so
index k on t is created as t__k and reported as k by SHOW INDEX /
information_schema.statistics; DROP INDEX k ON t and ALTER TABLE t DROP
{INDEX|KEY} k drop it, falling back to an index of t created under the bare
name by an older litewire. Unnamed keys get MySQL's default names; an
unnamed ALTER ... ADD INDEX no longer emits invalid SQL.
Column CHARACTER SET / COLLATE / COMMENT / ON UPDATE and charset
introducers (_binary '...' becomes a blob literal) no longer reach SQLite.
tests/mysql_dump_restore.rs replays an unedited MySQL 8.4 mysqldump
--hex-blob (fixtures/) plus a ~700 KB extended INSERT on both backends and
checks schema, keys, data, key enforcement and AUTO_INCREMENT continuation.
Restore guide in docs/sql-translation.md.
…tes KEY k (col DESC))
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.
Restoring a MySQL 8.4
mysqldumpthrough litewire now brings back the indexes, and DDL with MySQL-only column syntax no longer fails.Indexes
KEY/INDEX/UNIQUE KEYinCREATE TABLEused to be dropped (KEY) or reduced to an anonymousUNIQUE (...)(UNIQUE KEY). That meant a restored dump had no secondary indexes, andSHOW INDEXreported unique keys assqlite_autoindex_*. Each key now becomes a namedCREATE [UNIQUE] INDEXemitted after the table. It isIF NOT EXISTSwhen the table is. Unnamed keys get MySQL's default name (first column, then_2, ...). FULLTEXT/SPATIAL keys are still dropped.list_idxon two tables in the fixture). So MySQL indexkon tabletis created as SQLite index`t__k`.SHOW INDEX,information_schema.statisticsandSHOW COLUMNS'Keyreport it ask.DROP INDEX k ON t,ALTER TABLE t DROP INDEX k, andALTER TABLE t DROP KEY k(which sqlparser cannot parse; it is normalized toDROP INDEX) all dropt__k. Compat: an index created under its bare name by an older litewire is still dropped. On "no such index", the session drops the one index oftwhose name isk.ALTER TABLE t ADD INDEX (cols)used to emit invalid SQL (CREATE INDEX ON t). It now gets MySQL's default name.ASC/DESCin an inline key's column list (KEY k (col DESC), which mysqldump writes) is dropped because sqlparser cannot parse it there. A standaloneCREATE INDEXkeeps it.Columns and literals
CHARACTER SET/COLLATE/COMMENT/ON UPDATE CURRENT_TIMESTAMPare dropped instead of reaching SQLite, which rejected them. This applies in bothCREATE TABLEandALTER TABLE ... ADD. Documented behaviour differences: text comparisons are binary (case-sensitive), unlike MySQL's_cidefault, andON UPDATEis not emulated._binary 'abc'becomesX'616263'(a BLOB), and_utf8mb4'x'becomes'x'.Tests
crates/litewire/tests/mysql_dump_restore.rsreplays an unedited MySQL 8.4.11mysqldump --hex-blob(tests/fixtures/mysqldump_8_4.sql, from a synthetic schema written for the test). The dump has conditional comments, LOCK/UNLOCK, DISABLE/ENABLE KEYS, mixed utf8mb3/utf8mb4 collations at table and column level,ROW_FORMAT/AUTO_INCREMENT/COMMENTtable options, column COLLATE/COMMENT/ON UPDATE, ENUM/DECIMAL, prefix-length keys, a key name reused across tables, and string escapes. The test adds a ~700 KB extended INSERT. It runs on rusqlite and Turso and checks tables,SHOW INDEXnames/order/uniqueness, data (unicode, escapes, blob bytes), UNIQUE enforcement (1062), and AUTO_INCREMENT continuation.Docs:
docs/sql-translation.mdhas an updated DDL section and a new "Restoring a mysqldump" guide. The guide calls out that views/triggers/routines inside/*!50001 */are skipped and that dumps with binary data need--hex-blob.