PHPackages                             t4web/migrations - 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. t4web/migrations

ActiveZf2-module[Database &amp; ORM](/categories/database)

t4web/migrations
================

ZF2 Module for database migrations management.

2.0.3(10y ago)0228BSD-3-ClausePHPPHP &gt;=5.5

Since Mar 1Pushed 9y ago4 watchersCompare

[ Source](https://github.com/t4web/Migrations)[ Packagist](https://packagist.org/packages/t4web/migrations)[ Docs](https://github.com/t4web/Migrations)[ RSS](/packages/t4web-migrations/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)Dependencies (9)Versions (7)Used By (0)

[![Build Status](https://camo.githubusercontent.com/e71bb9b059f61359a334c63a10a5728147142a264262805fb7377c49b7accf52/68747470733a2f2f7472617669732d63692e6f72672f74347765622f4d6967726174696f6e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/t4web/Migrations)[![codecov.io](https://camo.githubusercontent.com/8e62eade7e0d2a4d4b592e34132d15b3b7c1906506c62c931c2f01fdba8ac9e3/687474703a2f2f636f6465636f762e696f2f6769746875622f74347765622f4d6967726174696f6e732f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/t4web/Migrations?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0da5053c75be9b6d37100721b4b6128703a54655fc85ebbcf81d31a67e746dad/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74347765622f4d6967726174696f6e732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/t4web/Migrations/?branch=master)

Migrations
==========

[](#migrations)

Simple Migrations for Zend Framework 2.

Supported Drivers
-----------------

[](#supported-drivers)

The following DB adapter drivers are supported by this module.

- Pdo\_Sqlite
- Pdo\_Mysql
- Mysqli *only if you configure the driver options with `'buffer_results' => true`*

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

[](#installation)

### Using composer

[](#using-composer)

```
php composer.phar require t4web/migrations
```

or add to your composer.json

```
"require": {
  "t4web/migrations": "^2.0.0"
}
```

Then add `T4web\Migrations` to the `modules` array in application.config.php

Configuration
-------------

[](#configuration)

### Add to your configuration:

[](#add-to-your-configuration)

```
'migrations' => array(
    'dir' => dirname(__FILE__) . '/../../../migrations',
    'namespace' => 'T4web\Migrations',
    'adapter' => 'Zend\Db\Adapter\Adapter',
    'show_log' => true
),
```

### General options:

[](#general-options)

The top-level key used to configure this module is `migrations`.

#### Migration Configurations: Migrations

[](#migration-configurations-migrations)

Each key under `migrations` is a migrations configuration.

##### Sub-key: `dir`

[](#sub-key-dir)

The path to the directory where migration files are stored. Defaults to `./migrations` in the project root dir.

##### Sub-key: `namespace`

[](#sub-key-namespace)

The class namespace that migration classes will be generated with. Defaults to `T4web\Migrations`.

##### Sub-key: `show_log` (optional)

[](#sub-key-show_log-optional)

Flag to log output of the migration. Defaults to `true`.

##### Sub-key: `adapter` (optional)

[](#sub-key-adapter-optional)

The service alias that will be used to fetch a `Zend\Db\Adapter\Adapter` from the service manager.

Usage
-----

[](#usage)

### Available commands

[](#available-commands)

- `migration version` - show last applied migration (`name` specifies a configured migration)
- `migration list [--all]` - list available migrations (`all` includes applied migrations)
- `migration apply [] [--force] [--down]` - apply or rollback migration
- `migration generate` - generate migration class

Migration classes are stored in `/path/to/project/migrations/` dir by default.

Generic migration class has name `Version_` and implement `T4web\Migrations\Migration\MigrationInterface`.

### Migration class example

[](#migration-class-example)

```
