Skip to content

Schemage

Schemage is a schema-first migration engine for PHP.

Define the desired schema with a PHP DSL, introspect the current database, review the calculated operations, and apply the migration through a lightweight CLI.

Core flow

database/schema.php
        │
        ▼
  Desired Metadata          Current Database
        │                         │
        │                         ▼
        │                  Driver Introspector
        │                         │
        └────────────┬────────────┘
                     ▼
                Diff Engine
                     ▼
             Logical Operations
                     ▼
          Driver Operation Planner
                     ▼
          Executable Operations
                     ▼
              SQL Generator
                     ▼
                 Migrator

Features

  • Schema-first PHP DSL
  • MySQL and MariaDB support
  • SQLite support, including table recreation planning
  • Automatic database introspection
  • Table, column, index, and foreign-key diffing
  • Explicit table and column renaming
  • Migration planning and SQL preview
  • Migration execution and history
  • Rollback support
  • SQL diff export and full-schema export
  • Destructive-operation protection
  • Optional model generation

Quick example

<?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();
    });
};

Run:

vendor/bin/schemage

Schemage prints the migration plan and asks for confirmation before applying it.