[12.x] Ensure make:migration generates unique timestamp prefixes#60769
Closed
pushpak1300 wants to merge 1 commit into
Closed
[12.x] Ensure make:migration generates unique timestamp prefixes#60769pushpak1300 wants to merge 1 commit into
pushpak1300 wants to merge 1 commit into
Conversation
Migrations are ordered by their Y_m_d_His timestamp prefix, which only has one-second resolution. Chained generator calls such as `make:model ABC -m && make:model XYZ -m` run within the same second, so both migrations receive an identical prefix. When prefixes tie, execution order falls back to the file name, which is harmless on SQLite but can run dependent migrations out of order on MySQL and Postgres. MigrationCreator now bumps the timestamp forward one second at a time until it finds a prefix that is not already used in the target directory, guaranteeing a deterministic order on every driver.
Member
Author
|
Superseded by the 13.x-targeted PR. |
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.
The papercut
Coding agents routinely scaffold models by chaining generator commands:
These run within the same second, so both migrations get an identical
Y_m_d_Histimestamp prefix.Migrations are ordered by that prefix, which only has one-second resolution. When prefixes tie, execution order falls back to the file name (alphabetical), which is not the creation order. This is harmless on SQLite — so test suites pass and the problem stays hidden — but on MySQL and Postgres it's a real bug: if
XYZ's migration depends on a table created byABC's migration, the alphabetical fallback can run them in the wrong order and the migration fails.Anonymous migration classes (#37598) fixed the class name collision, but not the ordering collision — two anonymous migrations can still share a prefix.
Why fix it in the framework
Laravel Boost already instructs agents to avoid generating migrations this way, but that's guidance, not a guarantee — any tool or script that scaffolds two migrations in one second reintroduces it. Handling it directly in the framework closes the papercut for good, regardless of how the migrations are generated.
Fix
MigrationCreator::getDatePrefix()now checks the target migration directory for an existing file using the computed prefix. If one exists, it nudges the timestamp forward one second at a time until it finds a free prefix, guaranteeing a deterministic order on every driver.Because
A && Bruns as two sequential processes, the first migration is written to disk before the second globs, so the collision is reliably detected. A test covers the bump.