Skip to content

fix(designer): apply schema changes as one statement, not a run of them - #548

Merged
EVWorth merged 1 commit into
mainfrom
fix/designer-atomic-alter
Sep 5, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/designer-atomic-alter

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Closes #379.

The bug

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 — 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::Transaction and commit only on full success. 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

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:

Form Table afterwards
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.

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:

  • a failed combined ALTER changes nothing — on both servers
  • the old separate form is pinned, showing the partial apply it caused
  • a rollback is shown not to undo DDL, so the rejected proposal doesn't have to be taken on trust

Plus four generator tests and four component tests. All eight fail against the previous version.

Two existing tests asserted api.executeQuery was 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

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]>
@EVWorth
EVWorth merged commit c50ff05 into main Sep 5, 2026
10 checks passed
@EVWorth
EVWorth deleted the fix/designer-atomic-alter branch September 5, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant