Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Migrations Version Comparator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. composer require softspring/doctrine-migrations-version-comparator
  2. If you are not using package auto-discovery, register the service provider in config/app.php.
  3. Read 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.
  4. Try it interactively with 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.

Implementation Patterns

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.

Gotchas and Tips

  • v5.6.0 ships no changelog body. The release notes only link to a GitHub compare URL (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.
  • Lexical ordering is not semantic ordering. Timestamp versions compare cleanly as strings; semantic versions (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".
  • Cross-namespace comparisons are the classic footgun. Migrations from different namespaces/bundles do not necessarily share a monotonic ordering. If your gate compares across namespaces, you can get a truthful-but-useless answer.
  • Table and path drift. Custom 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.
  • Config caching. If you add config for this, remember php artisan config:clear locally and that production config caches will not pick up a new key until a fresh deploy.
  • Doctrine Migrations major-version API drift. Upgrading doctrine/migrations can change how 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.
  • Debug with real data. Dump the actual strings being compared (dd($a, $b)) rather than the objects — most "it says A is before B" surprises are whitespace, case, or a truncated version string.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings