eril/schemage

Schema-first database migration engine for PHP.

Maintainers

Package info

github.com/erilshackle/php-schemage

Homepage

pkg:composer/eril/schemage

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-07-11 21:09 UTC

This package is auto-updated.

Last update: 2026-07-13 00:46:55 UTC


README

Schema-first database migrations for PHP.

Schemage lets you describe the desired database structure with a clean PHP DSL, compare it with the current database, review a migration plan, generate SQL, and apply the required changes through a lightweight CLI.

PHP Tests License

Features

  • Schema-first PHP DSL
  • MySQL, MariaDB, and SQLite support
  • Database introspection and schema diffing
  • Table, column, index, and foreign-key operations
  • Explicit table and column renames
  • Driver-specific operation planning
  • Interactive migration plans
  • Dry-run and SQL export modes
  • Migration history and rollback support
  • Destructive-operation protection
  • Optional model generation

Installation

composer require eril/schemage

Quick Start

<?php

use Schemage\DSL\Schema;
use Schemage\DSL\Table;

return function (Schema $schema): void {
    $schema->table('users', function (Table $t): void {
        $t->id();
        $t->string('name');
        $t->string('email')->unique('users_email_unique');
        $t->timestamps();
    });
};

Preview pending changes:

vendor/bin/schemage --dry-run

Apply interactively:

vendor/bin/schemage

Apply without confirmation:

vendor/bin/schemage --yes

For non-interactive destructive migrations:

vendor/bin/schemage --yes --force

Initial Data

Tables may declare default rows using seed():

$schema->table('roles', function (Table $t) {
    ...
})->seed([
    ['id' => 1, 'code' => 'admin'],
    ['id' => 2, 'code' => 'user'],
]);

Declared rows are inserted automatically after migrations and ignored if they already exist.

Documentation

Full documentation is available online:

https://erilshackle.github.io/schemage/

Documentation includes:

Start with:

  • docs/getting-started.md
  • docs/schema.md
  • docs/columns.md
  • docs/indexes.md
  • docs/foreign-keys.md
  • docs/cli.md

License

MIT