Skip to content
Muhammet Şafak edited this page Jun 11, 2026 · 2 revisions

InitPHP Barbarian — Wiki

Welcome to the official documentation for initphp/barbarian — a small, dependency-light database migration library for PHP. It discovers your migration classes on disk, keeps a version table in sync, and runs the up()/down() side of each migration either from your own code or through a simple command-line interface.

composer require initphp/barbarian
<?php

declare(strict_types=1);

namespace App\Migrations;

use InitPHP\Barbarian\MigrationAbstract;
use InitPHP\Barbarian\QueryInterface;

final class Migration_20240101000000 extends MigrationAbstract
{
    public function up(QueryInterface $query): bool
    {
        $query->query('CREATE TABLE IF NOT EXISTS `users` (
            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
            `name` VARCHAR(255) NOT NULL,
            PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');

        return true;
    }

    public function down(QueryInterface $query): bool
    {
        $query->query('DROP TABLE IF EXISTS `users`');

        return true;
    }
}
vendor/bin/barbarian status   # up / down / pending for every migration
vendor/bin/barbarian up       # apply all migrations
vendor/bin/barbarian down     # revert all migrations (reverse order)

The building blocks

Type Purpose
Migrations Discovers migrations, keeps the version table in sync, runs up()/down().
MigrationInterface The contract every migration fulfils.
MigrationAbstract Base class implementing getName() for you.
QueryInterface The query gateway handed to each migration.
QueryRunner Default QueryInterface: a thin PDO wrapper.
MigrationStatus Enum: Down = 0, Up = 1.
Schema\Grammar Driver-specific version table DDL and identifier quoting.
MigrationException Raised for failures in Barbarian itself.
Console\* Configuration loading, the manager factory and the CLI commands.

Start here

Core concepts

Term Meaning
Migration A class implementing MigrationInterface (usually via MigrationAbstract) with up() and down().
Version name The unqualified class name (e.g. Migration_20240101000000); the unique key in the version table.
Version table A table (default migrations_versions) recording each migration's status and last change time.
Manager Migrations — discovers migrations, ensures the version table and runs migrations.
Query gateway QueryInterface (implemented by QueryRunner) — the object passed to every up()/down().

Package metadata

If something in this wiki is unclear, ambiguous, or wrong, please open an issue — documentation fixes are reviewed eagerly.

Clone this wiki locally