Repository navigation
fix(designer): apply schema changes as one statement, not a run of them - #548
Merged
Merged
Conversation
Closes #379. Apply Changes emitted one ALTER TABLE per change and sent them as a single multi-statement string. A failure partway through left everything before it applied. Adding five columns where the third collides with an existing name left the first two added and the table in a shape nobody asked for. The issue proposes wrapping the statements in a transaction. That cannot work: DDL commits implicitly. Verified on MySQL 8 — START TRANSACTION; ALTER TABLE t ADD COLUMN a INT; ROLLBACK; -> the column is still there What does work is putting every change in one ALTER TABLE, since a statement that fails makes no change at all. Verified on MySQL 8 and MariaDB 11, same collision either way: separate statements -> id, dup, ok1 (the first one landed) one statement -> id, dup (untouched) Everything the generator emits is a legal clause of one ALTER — RENAME TO, ADD/DROP/MODIFY/CHANGE COLUMN, index and foreign key clauses, and the table options — so the whole diff becomes one statement, one clause per line so the preview stays readable. Both servers accept the combined form including a rename alongside other clauses, which was worth checking rather than assuming. Saving also went straight to api.executeQuery, skipping the result store. That is where the production gate lives and where history entries are written, so a schema change on a connection marked production ran with no confirmation and left no record. It goes through the store now, for CREATE as well as ALTER, and reports the store's error rather than claiming success. While the production dialog is open nothing has run, so the baseline does not move and success is not announced. Three integration tests per the behaviour rather than the intent: a failed combined ALTER changes nothing, on both servers; the old separate form is pinned showing the partial apply it caused; and a rollback is shown not to undo DDL, so the rejected proposal does not have to be taken on trust. Four generator tests and four component tests, all eight failing against the previous version. Two existing tests asserted api.executeQuery was called on save and now assert the store instead — the assertion moved because the behaviour did, not because it was wrong. Not addressed: the query timeout, which the issue also lists. That is a connection-level setting the store does not currently pass through for any caller, so it belongs with that rather than here. 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 #379.
The bug
Apply Changes emitted one
ALTER TABLEper change and sent them as a single multi-statement string. A failure partway through left everything before it applied — five columns added where the third collides leaves the first two in place and the table in a shape nobody asked for.The proposed fix cannot work
The issue says to wrap the statements in a
sqlx::Transactionand commit only on full success. DDL commits implicitly. Verified on MySQL 8:What does work
Putting every change in one
ALTER TABLE. A statement that fails makes no change at all. Verified on MySQL 8 and MariaDB 11, same collision either way:id, dup, ok1— the first one landedid, dup— untouchedEverything the generator emits is a legal clause of one ALTER —
RENAME TO,ADD/DROP/MODIFY/CHANGE COLUMN, index and foreign key clauses, and the table options — so the whole diff becomes one statement, one clause per line so the preview stays readable. Both servers accept the combined form including a rename alongside other clauses, which was worth checking rather than assuming.The other half
Saving went straight to
api.executeQuery, skipping the result store — which is where the production gate lives and where history entries are written. A schema change on a connection marked production ran with no confirmation and no record. It goes through the store now, for CREATE as well as ALTER, and reports the store's error instead of claiming success. While the production dialog is open nothing has run, so the baseline doesn't move and success isn't announced.Tests
Three integration tests written against the behaviour rather than the intent:
Plus four generator tests and four component tests. All eight fail against the previous version.
Two existing tests asserted
api.executeQuerywas called on save and now assert the store — the assertion moved because the behaviour did, not because it was wrong. Flagging it so it isn't mistaken for a test being bent to fit.50 integration tests against live servers, 1750 unit + 298 browser, clippy/tsc/dprint/eslint clean.
Not addressed
The query timeout, which the issue also lists. It's a connection-level setting the store doesn't currently pass through for any caller, so it belongs with that rather than being special-cased here.
🤖 Generated with Claude Code