Repository navigation
fix(designer): keep column modifiers through an edit instead of dropping them - #547
Merged
Merged
Conversation
…ing them Closes #377. A column was loaded by taking the leading word of COLUMN_TYPE as the type and whatever was in brackets as the length. Everything else was discarded. `int(10) unsigned zerofill` came back as INT and "10", so editing that column — its name, its comment, anything — emitted MODIFY COLUMN `big` INT(10) NOT NULL and the column stopped being unsigned. Confirmed against MySQL 8, both ways it can go: - strict mode, the default: the ALTER fails outright with ERROR 1264 when a row holds more than 2^31-1, and where no row does it succeeds and leaves a signed column that rejects those values from then on - strict mode off: existing data is clamped. 4000000000 became 2147483647, with no error CHARACTER SET and COLLATE went the same way, falling back to the table default, and `ON UPDATE CURRENT_TIMESTAMP` was dropped because it lives in EXTRA rather than in the type. Charset and collation are not in COLUMN_TYPE at all, so get_columns now selects CHARACTER_SET_NAME and COLLATION_NAME as well; ColumnInfo carries both as Option, since they are only set when a column overrides the table. parseColumnType reads the rest out of COLUMN_TYPE and parseOnUpdate takes the ON UPDATE half of EXTRA — only that half, since the DEFAULT_GENERATED that precedes it describes the DEFAULT and must not be re-emitted. DesignerColumn carries the five as optional fields and buildColumnDef puts each where MySQL requires it: UNSIGNED and ZEROFILL as part of the type, CHARACTER SET and COLLATE between the type and NOT NULL, ON UPDATE after DEFAULT. isColumnChanged compares them too, so asking to drop UNSIGNED is a change rather than a no-op. No new controls. The designer still cannot set these deliberately; it just stops destroying them. Adding the controls is a feature, and the type-list gaps behind the VARCHAR fallback are #382. Verified on both servers, which round-trip the emitted statements with the column reported back unchanged and the 4000000000 still stored: big int(10) unsigned zerofill s varchar(20) utf8mb4_bin ts timestamp on update CURRENT_TIMESTAMP Ten unit tests on the parsers, five on the generator, and one integration test per server. Four of the five generator tests fail against the previous version; the fifth asserts an untouched column still emits nothing. The issue's repro says to click Apply Changes without editing anything. That emits no statement at all — the diff only produces MODIFY for a column that differs — so the damage needs an edit to the column in question. The bug is real; that path to it is not. Co-Authored-By: Claude Opus 5 <[email protected]>
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.
Closes #377.
What was wrong
A column was loaded by taking the leading word of
COLUMN_TYPEas the type and whatever was in brackets as the length. Everything else was discarded.int(10) unsigned zerofillcame back asINTand"10", so editing that column — its name, its comment, anything — emitted:and the column stopped being unsigned.
Confirmed against MySQL 8, both ways it can go:
ERROR 1264when a row holds more than 2^31-1. Where no row does, it succeeds — leaving a signed column that rejects those values from then on.4000000000became2147483647.CHARACTER SETandCOLLATEwent the same way, falling back to the table default, andON UPDATE CURRENT_TIMESTAMPwas dropped because it lives inEXTRArather than in the type.The fix
Charset and collation aren't in
COLUMN_TYPEat all, soget_columnsnow also selectsCHARACTER_SET_NAMEandCOLLATION_NAME;ColumnInfocarries both asOption, since they're only set when a column overrides the table's.parseColumnTypereads the rest out ofCOLUMN_TYPE, andparseOnUpdatetakes theON UPDATEhalf ofEXTRA— only that half, since theDEFAULT_GENERATEDpreceding it describes the DEFAULT and must not be re-emitted.buildColumnDefputs each where MySQL requires it: UNSIGNED/ZEROFILL as part of the type, CHARACTER SET/COLLATE between the type and NOT NULL, ON UPDATE after DEFAULT.isColumnChangedcompares them too, so asking to drop UNSIGNED is a change rather than a no-op.No new controls. The designer still can't set these deliberately; it just stops destroying them. Adding the controls is a feature, and the type-list gaps behind the
VARCHARfallback are #382.Verified on both servers
MySQL 8 and MariaDB 11 both round-trip the emitted statements with the column reported back unchanged and the value still stored:
Ten unit tests on the parsers (including an
ENUMwhose members contain a bracket, and one whose members are literally'unsigned','zerofill'), five on the generator, one integration test per server. Four of the five generator tests fail against the previous version; the fifth asserts an untouched column still emits nothing.46 integration tests against live servers, 1742 unit + 298 browser, clippy/tsc/dprint/eslint clean.
One correction to the issue
Its repro says to click Apply Changes without editing anything. That emits no statement at all — the diff only produces a
MODIFYfor a column that differs — so the damage needs an edit to the column in question. The bug is real and serious; that particular path to it isn't. Same pattern as #378, where the stated repro also didn't hold.🤖 Generated with Claude Code