PHPackages                             turanct/migraine - 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. turanct/migraine

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

turanct/migraine
================

0.1.0(4y ago)3491MITPHPPHP &gt;=7.1CI failing

Since Sep 19Pushed 4y ago2 watchersCompare

[ Source](https://github.com/turanct/migraine)[ Packagist](https://packagist.org/packages/turanct/migraine)[ Docs](https://github.com/turanct/migraine)[ GitHub Sponsors](https://github.com/turanct)[ RSS](/packages/turanct-migraine/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (9)Used By (0)

🤯 Migraine
==========

[](#-migraine)

[![Build Status](https://camo.githubusercontent.com/29e51fb40ebc248fbb7643f6c1f6e9a04d5e80ad19145e207bd124234de64a3f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f747572616e63742f6d69677261696e652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/turanct/migraine)[![PHPUnit tests](https://github.com/turanct/migraine/actions/workflows/tests.yaml/badge.svg)](https://github.com/turanct/migraine/actions/workflows/tests.yaml)[![Linters](https://github.com/turanct/migraine/actions/workflows/psalm.yaml/badge.svg)](https://github.com/turanct/migraine/actions/workflows/psalm.yaml)

A simple way of providing database migrations to your project

Disclaimer
----------

[](#disclaimer)

Use this package at your own risk.

Goals
-----

[](#goals)

- Write migrations as simple SQL statements
- Be framework agnostic
- Run migrations on multiple databases
- Run different migrations on different groups of databases
- Allow seeding of the databases
- Keep logs in SQL itself
- Have the ability to roll back migrations

Usage
-----

[](#usage)

### Install using Composer

[](#install-using-composer)

```
composer require "turanct/migraine"
```

### Provide a config file

[](#provide-a-config-file)

In this example we have two **groups**, `main` which is the main database, and `shards` which is a group of sharded databases. The difference between `main` and `shards` (in production) is that `shards` contains of multiple databases which all need to look the same. This means that if we do a migration, we'll run it on all those databases.

`migrations.json`

```
{
    "directory": "migrations",
    "groups": {
        "main": {
            "connection": "mysql:host=127.0.0.1;port=3306;dbname=main",
            "user": "user",
            "password": "password"
        },
        "shards": {
            "user": "user",
            "password": "password",
            "shard1": {
                "connection": "mysql:host=127.0.0.1;port=3306;dbname=shard1"
            },
            "shard2": {
                "connection": "mysql:host=127.0.0.1;port=3306;dbname=shard2"
            },
            "shard3": {
                "connection": "mysql:host=127.0.0.1;port=3306;dbname=shard3"
            },
            "shard4": {
                "connection": "mysql:host=127.0.0.1;port=3306;dbname=shard4"
            }
        }
    }
}
```

By default, migraine will log the migrations that are done in `logs.json` in your working directory, however this is configurable:

#### Logging in a different file

[](#logging-in-a-different-file)

`migrations.json`

```
{
    "directory": "migrations",
    "logs": {
        "type": "json",
        "file": "alternative-file.json"
    },
    "groups": {
        ...
    }
}
```

#### Logging in SQL

[](#logging-in-sql)

`migrations.json`

```
{
    "directory": "migrations",
    "logs": {
        "type": "sql",
        "connection": "mysql:host=127.0.0.1;port=3306;dbname=main",
        "user": "user",
        "password": "password",
        "table": "logs"
    },
    "groups": {
        ...
    }
}
```

### Prepare your migrations directory

[](#prepare-your-migrations-directory)

```
mkdir migrations
mkdir migrations/main
mkdir migrations/shards
```

### Add some migrations

[](#add-some-migrations)

You can use the `new` command to create a new migration:

```
vendor/bin/migraine new main "create users tabel"
```

it will create this file: `migrations/main/20200426195623000-create-users-table.sql`

We'll fill it with the migration we want to run:

```
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `lastupdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
```

and this command for the `shards`:

```
vendor/bin/migraine new shards "create data tabel"
```

will create this file: `migrations/shards/20200426195959000-create-data-table.sql`

We'll fill it with the migration we want to run:

```
CREATE TABLE IF NOT EXISTS `data` (
  `id` int(11) NOT NULL,
  `userId` int(11) NOT NULL,
  `data` text,
  `lastupdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
```

### Run the migrations

[](#run-the-migrations)

This is how you run all migrations. We'll automatically dry-run your migration:

```
vendor/bin/migraine migrate
```

If you want to commit to the migration you just did a dry-run for, commit:

```
vendor/bin/migraine migrate --commit
```

If you want to only migrate a given group, specify it:

```
vendor/bin/migraine migrate --group shards --commit
```

If you want to only run a specific migration, specify it:

```
vendor/bin/migraine migrate --migration 20200426195959000-create-data-table.sql --commit
```

If you want to skip a migration (e.g. because you know it was already done manually):

```
vendor/bin/migraine skip --migration 20200426195959000-create-data-table.sql --commit
```

Use the skip functionality with caution. It writes a skipped log to the log file, and will never run this migration again, just like the migration was actually executed.

### Seeding

[](#seeding)

You can create seeds by adding a `/seeds` directory to a group's directory. In that directory, you can add files just like any other migration.

```
mkdir main/seeds

touch main/seeds/20200426195623000-seed-users.sql
```

it will create this file: `migrations/main/seeds/20200426195623000-seed-users.sql`

Fill it with the migration you want to run:

```
INSERT INTO `users` (`id`, `name`, `email`)
VALUES ('1', 'admin', 'admin@example.com');
```

If you want to apply a specific seed, specify it

```
vendor/bin/migraine seed --seed seeds/20200426195623000-seed-users
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email [spinnewebber\_toon@hotmail.com](mailto:spinnewebber_toon@hotmail.com) instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Total

8

Last Release

1749d ago

PHP version history (2 changes)0.0.1PHP ~7.1

0.0.6PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/fcdce4f02b6e4e353431c361e9f193fa469f59cf3eddeca683b6f74efc8efa28?d=identicon)[turanct](/maintainers/turanct)

---

Top Contributors

[![turanct](https://avatars.githubusercontent.com/u/1728360?v=4)](https://github.com/turanct "turanct (72 commits)")

---

Tags

databasemigrations

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/turanct-migraine/health.svg)

```
[![Health](https://phpackages.com/badges/turanct-migraine/health.svg)](https://phpackages.com/packages/turanct-migraine)
```

###  Alternatives

[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k46.2M403](/packages/robmorgan-phinx)[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M186](/packages/spatie-laravel-backup)[doctrine/migrations

PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.

4.8k204.8M438](/packages/doctrine-migrations)[lulco/phoenix

Database Migrations for PHP

180329.4k4](/packages/lulco-phoenix)[bartlett/php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions

1183.0k1](/packages/bartlett-php-compatinfo-db)[perplorm/perpl

Perpl is an improved and still maintained fork of Propel2, an open-source Object-Relational Mapping (ORM) for PHP.

203.7k](/packages/perplorm-perpl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
