Skip to content

fix(migration): make kyte_locked migration portable to MySQL (v4.15.1, KYTE-#325)#112

Merged
kennethphough merged 1 commit into
masterfrom
fix/415-portable-kyte-locked-migration
Jul 1, 2026
Merged

fix(migration): make kyte_locked migration portable to MySQL (v4.15.1, KYTE-#325)#112
kennethphough merged 1 commit into
masterfrom
fix/415-portable-kyte-locked-migration

Conversation

@kennethphough

Copy link
Copy Markdown
Member

What

Rewrites migrations/4.15.0_datamodel_kyte_locked.sql to be engine-portable (MySQL + MariaDB), replacing the MariaDB-only ADD COLUMN IF NOT EXISTS with an information_schema guard + prepared statement. Ships as v4.15.1.

Why

The migration (added in #111) used ALTER TABLE ... ADD COLUMN IF NOT EXISTS, which is MariaDB-only — it's a syntax error on MySQL 5.7/8.0. This surfaced during the v4.15.0 rollout to the first MySQL-backed install (ETOM, MySQL 8.0.44).

  • No install was harmed: ETOM's kyte_locked columns already existed, so the failed statement was a no-op, and the decimal migration (portable) succeeded. The MariaDB clients applied the original fine.
  • But it was latently broken: a drifted MySQL install would have errored and never gained the column, leaving the v4.15.0 model-level lock guard inert — the opposite of the migration's purpose.

Fix

Idempotent, portable pattern:

SET @col_exists := (SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='DataModel' AND COLUMN_NAME='kyte_locked');
SET @ddl := IF(@col_exists=0, 'ALTER TABLE `DataModel` ADD COLUMN `kyte_locked` INT UNSIGNED NULL DEFAULT 0', 'DO 0');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;

(repeated for ModelAttribute).

Validation

Ran the new pattern live against both engines — clean, exit 0, columns intact:

  • MySQL 8.0.44 (ETOM shipyard) — the engine that rejected the old syntax
  • MariaDB 11.8.6 (dev)

Impact

Migration-only; no PHP change. Installs already on v4.15.0 with the columns present need no action — the deployed clients do not require re-rolling. Protects future/fresh/drifted MySQL installs.

🤖 Generated with Claude Code

…, KYTE-#325)

migrations/4.15.0_datamodel_kyte_locked.sql used MariaDB-only
`ALTER TABLE ... ADD COLUMN IF NOT EXISTS`, which is a syntax error on MySQL
5.7/8.0. Surfaced during the v4.15.0 rollout to the first MySQL-backed install
(ETOM, MySQL 8.0.44) — no harm there since its kyte_locked columns already
existed (failed stmt was a no-op) and the decimal migration is portable, but a
drifted MySQL install would have errored and never gained the column, leaving
the model-level lock guard inert.

Rewritten with an information_schema column check + a prepared statement, which
is idempotent on BOTH MySQL and MariaDB. Validated live: clean no-op on
MySQL 8.0.44 and MariaDB 11.8.6.

Migration-only; no PHP behavior change. Installs already on v4.15.0 with the
columns present need no action. CHANGELOG: 4.15.1 section added.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kennethphough
kennethphough merged commit 97e5a08 into master Jul 1, 2026
4 checks passed
@kennethphough
kennethphough deleted the fix/415-portable-kyte-locked-migration branch July 1, 2026 08: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

Development

Successfully merging this pull request may close these issues.

1 participant