PHPackages                             initphp/barbarian - 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. initphp/barbarian

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

initphp/barbarian
=================

Small, dependency-light database migration library for PHP with a PDO-based runner and a CLI.

2.0.0(3w ago)012MITPHPPHP &gt;=8.1CI passing

Since Jul 7Pushed 3w ago1 watchersCompare

[ Source](https://github.com/InitPHP/Barbarian)[ Packagist](https://packagist.org/packages/initphp/barbarian)[ Docs](https://github.com/InitPHP/Barbarian)[ RSS](/packages/initphp-barbarian/feed)WikiDiscussions main Synced today

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

Barbarian
=========

[](#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 programmatically or through a simple command-line interface.

[![CI](https://github.com/InitPHP/Barbarian/actions/workflows/ci.yml/badge.svg)](https://github.com/InitPHP/Barbarian/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/d881768e467b959e889998a90bb6968f5d3b95055a84ab4b599ac4e3e0083a0c/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f62617262617269616e2f76)](https://packagist.org/packages/initphp/barbarian)[![License](https://camo.githubusercontent.com/db524dc0d06e230d3fb4e58b858c9d0aa432b24308101198006121b707a0107e/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f62617262617269616e2f6c6963656e7365)](https://packagist.org/packages/initphp/barbarian)

Features
--------

[](#features)

- Plain PDO under the hood — works with **MySQL/MariaDB**, **SQLite** and **PostgreSQL**.
- A tracked version table so each migration is applied (or reverted) exactly once.
- Idempotent `up`/`down` with an optional `force` to re-run.
- A small CLI (`init`, `create`, `status`, `up`, `down`) built on [InitPHP Console](https://github.com/InitPHP/Console).
- Fully typed, PSR-12 compliant, analysed with PHPStan and covered by tests.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- `ext-pdo` and the PDO driver for your database (`pdo_mysql`, `pdo_sqlite` or `pdo_pgsql`)
- `ext-json`
- [initphp/console](https://github.com/InitPHP/Console) `^2.1` (installed automatically)

Installation
------------

[](#installation)

```
composer require initphp/barbarian
```

Writing a migration
-------------------

[](#writing-a-migration)

A migration extends `InitPHP\Barbarian\MigrationAbstract` and implements `up()`and `down()`. Each method receives a `QueryInterface` to run statements with and returns a `bool`: returning `false` (or throwing) tells the runner **not** to record the state change, so the migration can be retried.

By convention, files are named `Migration_.php` and the class name matches the file name.

```
