Skip to content

fix(migrations): finish the adhoc dispatch migration on MySQL 8.4 and after a failed run - #429

Merged
roncodes merged 1 commit into
release/v0.7.1from
fix/adhoc-migration-rerun
Nov 18, 2026
Merged

roncodes merged 1 commit into
release/v0.7.1from
fix/adhoc-migration-rerun

Conversation

@roncodes

@roncodes roncodes commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Fixes the v0.8.0 production deploy, which failed in this migration with SQLSTATE[HY000]: 1553 Cannot drop index '<unknown key name>': needed in a foreign key constraint on alter table order_configs add policies json null.

Cause

Production runs MySQL 8.4.8, which turns on restrict_fk_on_non_standard_key by default. order_configs.uuid has an ordinary, non-unique index, and four foreign keys point at it: from orders, service_rates, and storefront's stores and networks, which are in the storefront database. With the setting on, MySQL rejects any ALTER of order_configs, even adding a nullable column. CI's MySQL 8.0 has no such setting, which is why this passed there.

Changes

  • Column changes run with restrict_fk_on_non_standard_key off for this session, and the previous value is restored afterwards, even if a step fails. Where the variable doesn't exist (MySQL before 8.4, MariaDB, SQLite), nothing changes.
  • Safe to re-run. MySQL doesn't roll back DDL, so the failed deploy left order_offers, driver_ratings and the three orders columns behind. Each table and column is now created only if it's missing, and down() drops only what exists. Definitions are unchanged.

Testing

I built production's shape for each run: order_configs.uuid with a plain index, child foreign keys from orders and service_rates, one from a second database, and the partial state the deploy left. Then I ran up(), up() again, down() and up():

Database Plain ALTER Migration
MySQL 8.4.8 fails with 1553, as in production passes; setting back to ON afterwards
MySQL 8.0.46 — passes; the variable doesn't exist, so it isn't touched
SQLite (Laravel 12.70.2) — passes

Not run: the full fleetops suite, which CI runs.

Follow-up

Any other table whose foreign keys point at a non-unique key will hit the same error the next time a migration alters it on MySQL 8.4. The lasting fix is to make those referenced uuid columns unique.

MySQL does not roll back DDL. The v0.8.0 production deploy failed at
order_configs, after order_offers, driver_ratings and the orders columns had
been created, so a re-run would fail on "table already exists". Each table
and column is now created only if missing, and down() drops only what exists.
@roncodes
roncodes merged commit 0391397 into release/v0.7.1 Nov 18, 2026
3 of 4 checks passed
@roncodes
roncodes deleted the fix/adhoc-migration-rerun branch November 18, 2026 03:15
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5f365b7) to head (9fed678).
⚠️ Report is 5 commits behind head on release/v0.7.1.

Additional details and impacted files
@@                Coverage Diff                 @@
##             release/v0.7.1      #429   +/-   ##
==================================================
  Coverage            100.00%   100.00%           
  Complexity            14702     14702           
==================================================
  Files                   676       676           
  Lines                 51313     51313           
==================================================
  Hits                  51313     51313           
Flag Coverage Δ
backend 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@roncodes roncodes changed the title fix(migrations): make the adhoc dispatch migration safe to re-run fix(migrations): finish the adhoc dispatch migration on MySQL 8.4 and after a failed run Nov 18, 2026
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