softspring/doctrine-migrations-version-comparator
A PHP utility that adds a version comparator for Doctrine migrations, making it easy to sort migration versions, check ordering, and determine whether one migration is newer or older than another in your project.
This package provides a comparator for Doctrine Migrations versions — the piece you need when you want to answer "is migration A before or after migration B?" programmatically instead of eyeballing timestamps in a directory listing.
Minimal steps:
composer require softspring/doctrine-migrations-version-comparatorconfig/app.php.src/ before the README — the surface area is small. Identify the comparator class (the thing implementing the version comparison) and any Doctrine config wiring/binding it ships with. That class is where 90% of your integration work will happen.php artisan tinker against two known migration class names from your database/migrations (or doctrine_migrations) directory. Confirm the ordering it returns matches the ordering Doctrine itself uses when running migrate.First real use case: a deploy guard. Before running doctrine:migrations:migrate, compare the highest version already recorded in the doctrine_migration_versions table against the highest version present on disk to decide whether there is anything to do, or to gate a post-deploy step (cache warm, backfill, feature flag flip) on a specific migration having been passed.
Comparator as a collaborator, not a string helper. Inject the comparator into your own application service rather than calling version_compare() inline. You then have one place to swap behaviour if your team moves between timestamped (Version20240512103000) and semantic version naming.
Deploy/CI gate. A small artisan command that returns a non-zero exit code when the shipped code contains migrations newer than the last applied version is the highest-leverage pattern. Wire it into your pipeline before the migrate step so a partially-deployed release fails loudly instead of silently running half a migration set.
Version-aware data migrations. Inside a data migration or seeder, compare the current migration version to a threshold and no-op if the threshold has not been crossed. This makes the migration safe to re-run in environments that were restored from a snapshot.
Ordering assertions in tests. In a feature test, assert that a specific migration sorts after a known baseline. That catches accidental renames and hand-edited version strings before they reach a shared environment, where Doctrine will happily skip or re-order them.
Binding the interface. If the package exposes an interface, bind it in a service provider and resolve it from the container everywhere. Keep the Doctrine-specific implementation out of your domain code — this is a build/deploy concern, not a business concern.
Pair with the Doctrine migrations configuration. Read the versions from the same source Doctrine reads them (doctrine_migrations table name, configured migration paths, configured namespace). If your comparator input comes from a stale cache or a different path than Doctrine's, the comparison is meaningless.
v5.5.10...v5.6.0) with no migration guide, breaking-change callout, or feature summary. Read that diff before bumping: check the composer.json constraint changes, any renamed classes, and any change to how versions are compared. Treat 5.6.0 as unverified until you have run your own version-ordering assertion tests against it.1.10.0 vs 1.9.0) do not. Confirm which convention the comparator applies to your format, and do not rely on it for versions from mixed naming schemes — Doctrine itself orders by namespace and name, not by "release significance".doctrine_migrations table names and non-default migration paths are the most common reason a comparator "returns the wrong thing". Verify what the comparator reads versus what Doctrine has configured.php artisan config:clear locally and that production config caches will not pick up a new key until a fresh deploy.Version objects are constructed and compared. Pin a compatible range in composer.json and let a test cover the comparison rather than discovering the drift in production.dd($a, $b)) rather than the objects — most "it says A is before B" surprises are whitespace, case, or a truncated version string.How can I help you explore Laravel packages today?