PHPackages                             izniburak/nur-migration - 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. izniburak/nur-migration

ActiveLibrary

izniburak/nur-migration
=======================

Simple migrations system for php

v2.0.0(1y ago)0454↓100%1MITPHPPHP ^8.1

Since Oct 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/izniburak/nur-migration)[ Packagist](https://packagist.org/packages/izniburak/nur-migration)[ Docs](https://github.com/izniburak/nur-migration)[ RSS](/packages/izniburak-nur-migration/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (4)Versions (11)Used By (0)

Phpmig
======

[](#phpmig)

[![Build Status](https://camo.githubusercontent.com/56934fd44c6e1b2c2a511df56cadac52ef2522a9dadd4c7d1f2ed4f039706069/68747470733a2f2f7472617669732d63692e6f72672f64617665646576656c6f706d656e742f7068706d69672e706e67)](https://travis-ci.org/davedevelopment/phpmig)

What is it?
-----------

[](#what-is-it)

Phpmig is a (database) migration tool for php, that should be adaptable for use with most PHP 5.3+ projects. It's kind of like [doctrine migrations](https://github.com/doctrine/migrations), without the [doctrine](https://github.com/doctrine). Although you can use doctrine if you want. And ironically, I use doctrine in my examples.

How does it work?
-----------------

[](#how-does-it-work)

```
$ phpmig migrate
```

Phpmig aims to be vendor/framework independent, and in doing so, requires you to do a little bit of work up front to use it.

Phpmig requires a bootstrap file, that must return an object that implements the ArrayAccess interface with several predefined keys. We recommend returning an instance of [Pimple](https://github.com/fabpot/Pimple), a simple dependency injection container. This is also an ideal opportunity to expose your own services to the migrations themselves, which have access to the container, such as a [schema management abstraction](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-manager.html).

Getting Started
---------------

[](#getting-started)

The best way to install phpmig is using composer:

```
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require davedevelopment/phpmig
```

You can then use the localised version of phpmig for that project

```
$ bin/phpmig --version
```

Phpmig can do a little configuring for you to get started, go to the root of your project and:

```
$ phpmig init
+d ./migrations Place your migration files in here
+f ./phpmig.php Create services in here
$
```

Note that you can move phpmig.php to config/phpmig.php, the commands will look first in the config directory than in the root.

Phpmig can generate migrations using the generate command. Migration files are named versionnumber\_name.php, where version number is made up of 0-9 and name is CamelCase or snake\_case. Each migration file should contain a class with the same name as the file in CamelCase.

```
$ phpmig generate AddRatingToLolCats
+f ./migrations/20111018171411_AddRatingToLolCats.php
$ phpmig status

 Status   Migration ID    Migration Name
-----------------------------------------
   down  20111018171929  AddRatingToLolCats

Use the migrate command to run migrations

$ phpmig migrate
 == 20111018171411 AddRatingToLolCats migrating
 == 20111018171411 AddRatingToLolCats migrated 0.0005s
$ phpmig status

 Status   Migration ID    Migration Name
-----------------------------------------
     up  20111018171929  AddRatingToLolCats
$
```

Better Persistence
------------------

[](#better-persistence)

The init command creates a bootstrap file that specifies a flat file to use to track which migrations have been run, which isn't great. You can use the provided adapters to store this information in your database.

```
