Skip to main content

Exceptions

Every exception the package throws implements Dirthara\Migration\Exception\MigrationException, so one catch handles all of them. Each carries a context array of non-sensitive details, such as the migration name, path, connection, or table, and wraps the failure of a dependency as its previous exception. Exceptions thrown by migration code itself, in up(), down(), or a hook, reach the caller unchanged.

All of them live in the Dirthara\Migration\Exception namespace.

ExceptionBaseThrown when
InvalidMigrationFileExceptionRuntimeExceptionA migration file or directory cannot be read, the file does not compile or throws while loading, or it returns no migration.
MigrationSourceLoaderExceptionRuntimeExceptionThe dirthara-migration stream wrapper scheme is taken by another component, or cannot be registered.
MigrationPlanExceptionRuntimeExceptionThe loaded migrations break a rule, the history conflicts with them, or a connection cannot be resolved.
MigrationRepositoryExceptionRuntimeExceptionThe migration history cannot be inspected, created, dropped, read, or written, or holds an invalid record.
MigrationLockExceptionRuntimeExceptionThe migration lock cannot be taken or released, or the history connection has no named locks.
MigrationRollbackExceptionRuntimeExceptionA migration selected for rollback has no source in the configured directories.
MigrationRefreshExceptionRuntimeExceptionA refresh cannot run the migrations again, because a rollback hook skipped or stopped the rollback.
MigrationFreshExceptionRuntimeExceptionA fresh run cannot drop the tables of one of the migration connections.
InvalidRollbackStepsExceptionInvalidArgumentExceptionrollback() or previewRollback() receives fewer than one step.
MigrationCreatorExceptionRuntimeExceptionA new migration has an invalid name, its template cannot be read, its file exists, or cannot be written.

Planning failures​

MigrationPlanException covers everything a run, rollback, refresh, fresh run, or preview checks before it changes anything:

FailureContext
Invalid namemigration, path
Empty indexmigration, path
Empty explicit connectionmigration, path
Duplicate namemigration, names, paths
Conflicting history namesmigration, conflictingMigration
Changed indexmigration, path, index, appliedIndex
Changed connectionmigration, path, connection, appliedConnection
Unresolvable connectionmigration, path, connection