Skip to main content
To record how long migrations take, listen for Illuminate\Database\Events\MigrationEnded. In Laravel 13.x, the time spent in the up or down method of a single successful migration is passed as duration.

What the event contains

MigrationEnded extends MigrationEvent and exposes the migration and the result of the run. In a normal migration run, duration is a float rounded to two decimal places. It can be null, for example when you create the event yourself, so check the value before your monitoring code uses it.

Logging the duration

Listen for the event in your application’s service provider and pass the data to the log as structured context.
Even when name is available, also logging migration::class makes it easier to identify the migration when it runs through a different path, such as an anonymous class. duration_ms is already in milliseconds, so you can send it to logs and metrics without converting it to another unit.

Event order

Laravel dispatches MigrationEnded only when up or down succeeds. A failed migration doesn’t dispatch MigrationEnded. Put the code that records the cause of a failure and its exception in a separate MigrationFailed listener, as described in Handling migration failures with the MigrationFailed event.

What is measured

The framework starts timing with microtime(true) right before it calls the migration method and stops right after up or down returns. The measurement therefore includes:
  • The PHP code inside the migration method
  • The database queries that method runs
  • Time spent waiting on the database while those queries run
It doesn’t include MigrationStarted listeners, MigrationEnded listeners, or the processing time of the whole migration batch. When schema transactions are used, the timing happens inside the transaction callback, so treat it separately from surrounding work such as starting and committing the transaction. This value doesn’t represent the time of the whole php artisan migrate command or of a batch containing several migrations. Use it to compare where time is spent in individual up / down methods.

Alerting on migrations over a threshold

Logging a warning only for migrations that exceed a certain time lets you detect slow changes without adding noise to your normal logs.
Choose the threshold based on your application’s data volume and deployment process. Don’t treat a long duration as a failure. Treat it as a “slowness” signal, separate from the exception data in MigrationFailed.

Checking the duration in tests

With Event::fake and Event::assertDispatched, you can check the shape of duration without running the real event listeners.
To monitor down durations as well, run migrate:rollback and check for events with method === 'down' in the same way. Durations depend on the environment and the state of the database, so test the type and that the value is non-negative rather than a specific number of milliseconds.

Summary

  • duration on MigrationEnded is the time, in milliseconds, that up / down of a single successful migration took.
  • Send durations to logs and metrics to detect slow migrations.
  • Event listeners and the whole batch aren’t included, so keep this separate from measuring the performance of the whole command.
  • Split monitoring responsibilities: MigrationFailed for failures, MigrationEnded for slowness in successful runs.

Primary sources

Last modified on November 28, 2026