PHPackages                             dakujem/migrun - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. dakujem/migrun

ActiveLibrary[Database &amp; ORM](/categories/database)

dakujem/migrun
==============

Lightweight, flexible, framework-and-database-agnostic migration runner.

1.0(1mo ago)011UnlicensePHPPHP ^8.2CI passing

Since Mar 28Pushed 1mo agoCompare

[ Source](https://github.com/dakujem/migrun)[ Packagist](https://packagist.org/packages/dakujem/migrun)[ RSS](/packages/dakujem-migrun/feed)WikiDiscussions trunk Synced 3w ago

READMEChangelog (2)Dependencies (5)Versions (4)Used By (0)

Migrun
======

[](#migrun)

[![Test Suite](https://github.com/dakujem/migrun/actions/workflows/php-test.yml/badge.svg)](https://github.com/dakujem/migrun/actions/workflows/php-test.yml)[![Coverage Status](https://camo.githubusercontent.com/2ec514b9aa829420456af31e654fe78cb1030d54b4e328d7ae2fc7f48a224c1a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f64616b756a656d2f6d696772756e2f62616467652e7376673f6272616e63683d7472756e6b)](https://coveralls.io/github/dakujem/migrun?branch=trunk)

A lightweight, flexible migration runner for your PHP stack.

Database migrations on your terms.
No framework lock-in. No config files. Any database.

> 💿 `composer require dakujem/migrun`

What is Migrun?
---------------

[](#what-is-migrun)

Migrun looks for migration files and makes sure each one has run exactly once. It is a lightweight, hackable tool to help you manage database changes consistently. It is intended to be incorporated into your existing project setup.

Migrun does **not**:

- provide a migration framework
- provide a query builder
- provide a database abstraction layer or any sort of ORM
- enforce usage of a particular database connection type or library

Migration file format
---------------------

[](#migration-file-format)

Migrun imposes **no restrictions on filenames**.
By default, any `.php` file placed in the configured directory is picked up as a migration.

Each migration MUST *return* a callable class or closure. This is a distinction compared to other migration runners.

### Execution order

[](#execution-order)

The built-in `DirectoryFinder` sorts migrations lexicographically by their ID, which is the filename stem (the path relative to the migrations directory, without the `.php` extension). **The order in which migrations run is therefore determined entirely by the filename.**

### Recommended naming convention

[](#recommended-naming-convention)

For execution order to match creation order, prefix each filename with a timestamp:

```
YYYYMMDD_HHMMSS_.php

```

Examples:

```
20240101_120000_create_users.php
20240115_093000_add_email_index.php

```

With this convention, lexicographic and chronological order coincide. Any other stable, monotonically increasing prefix (a sequential number, a date-only stamp, etc.) works just as well — pick whatever your team finds clearest.

> The timestamp in the filename is purely for ordering. The history storage records the time the migration *ran*, not the time encoded in the filename.

### Format A — anonymous class (up + down)

[](#format-a--anonymous-class-up--down)

The file **returns** an anonymous class with `up()` and `down()` methods. No interface required. Typed parameters are autowired from the PSR-11 container by class name (when using `ContainerInvoker`).

```
