Search by

cycle / migrations

wolfy-j

Database migrations, migration scaffolding

Package info

github.com/cycle/migrations

pkg:composer/cycle/migrations

Statistics

Installs: 743 194

Dependents: 41

Suggesters: 5

Stars: 21

Open Issues: 10

v4.4.0 2026-11-21 11:52 UTC

README

CycleORM Logo

Database migrations and migration scaffolding for Cycle ORM

Documentation Sponsor Discord

Psalm Level Type Coverage Codecov Mutation testing badge


Migrations are a convenient way for you to alter your database in a structured and organized manner. This package adds additional functionality for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.

Get Started

Installation

Requires PHP 8.2+.

composer require cycle/migrations

PHP Latest Version on Packagist License Total Downloads

Configuration

use Cycle\Migrations;
use Cycle\Database;
use Cycle\Database\Config;

$dbal = new Database\DatabaseManager(new Config\DatabaseConfig([
    'default' => 'default',
    'databases' => [
        'default' => [
            'connection' => 'sqlite'
        ]
    ],
    'connections' => [
        'sqlite' => new Config\SQLiteDriverConfig(
            connection: new Config\SQLite\MemoryConnectionConfig(),
            queryCache: true,
        ),
    ]
]));

$config = new Migrations\Config\MigrationConfig([
    'directory' => __DIR__ . '/../migrations/',    // where to store migrations
    'vendorDirectories' => [                       // Where to look for vendor package migrations
        __DIR__ . '/../vendor/vendorName/packageName/migrations/'
    ],
    'table' => 'migrations',                      // database table to store migration status
    'safe' => true,                               // When set to true no confirmation will be requested on migration run. 
]);

$migrator = new Migrations\Migrator(
    $config, 
    $dbal, 
    new Migrations\FileRepository($config)
);

// Init migration table
$migrator->configure();

Running

while (($migration = $migrator->run()) !== null) {
    echo 'Migrate ' . $migration->getState()->getName();
}

Generate Migrations

You can automatically generate a set of migration files during schema compilation. In this case, you have the freedom to alter such migrations manually before running them. To achieve that you must install the Schema migrations generator extension.