PHPackages                             console-helpers/db-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. [Database &amp; ORM](/categories/database)
4. /
5. console-helpers/db-migration

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

console-helpers/db-migration
============================

Database migrations made simple

v0.2.0(1y ago)14.2k—0%1[2 issues](https://github.com/console-helpers/db-migration/issues)1BSD-3-ClausePHPPHP &gt;=5.6CI failing

Since Jun 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/console-helpers/db-migration)[ Packagist](https://packagist.org/packages/console-helpers/db-migration)[ RSS](/packages/console-helpers-db-migration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (1)

DB-Migration
============

[](#db-migration)

[![CI](https://github.com/console-helpers/db-migration/actions/workflows/tests.yml/badge.svg)](https://github.com/console-helpers/db-migration/actions/workflows/tests.yml)[![codecov](https://camo.githubusercontent.com/e55344653981351c164b0505a58751664cd495d755f8bc840fded750aab4bab4/68747470733a2f2f636f6465636f762e696f2f67682f636f6e736f6c652d68656c706572732f64622d6d6967726174696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d5534676b73666a59596a)](https://codecov.io/gh/console-helpers/db-migration)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4c51d9e7a73c714d656fc62f0610f1f32a814fb305e3c721dedd0666a8f923fb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6e736f6c652d68656c706572732f64622d6d6967726174696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/console-helpers/db-migration/?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/f6efb0e1599bc25d8a23f54855e4d062bd08fb29ab92c5cc02cc4006c3c8f839/68747470733a2f2f706f7365722e707567782e6f72672f636f6e736f6c652d68656c706572732f64622d6d6967726174696f6e2f762f737461626c65)](https://packagist.org/packages/console-helpers/db-migration)[![Total Downloads](https://camo.githubusercontent.com/59f33ed1f10d4c3119f93ba9831dd444d25fd4e2fdb134511dd576bd4a5a0381/68747470733a2f2f706f7365722e707567782e6f72672f636f6e736f6c652d68656c706572732f64622d6d6967726174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/console-helpers/db-migration)[![License](https://camo.githubusercontent.com/3ac737d42a98b5504afdce549c1fb0dc7c84ac9f217fc2f11de6b01e3469e601/68747470733a2f2f706f7365722e707567782e6f72672f636f6e736f6c652d68656c706572732f64622d6d6967726174696f6e2f6c6963656e7365)](https://packagist.org/packages/console-helpers/db-migration)

DB-Migration is a library allows to run migrations on SQLite databases with ease.

Goals, when developing the library:

- allow initializing library without knowing database connection details upfront
- allow creating new migration file without knowing database connection details upfront
- allow using several databases in parallel
- being framework agnostic

Usage
-----

[](#usage)

### Initialization

[](#initialization)

```
use ConsoleHelpers\DatabaseMigration\MigrationManager;
use ConsoleHelpers\DatabaseMigration\PhpMigrationRunner;
use ConsoleHelpers\DatabaseMigration\SqlMigrationRunner;
use Pimple\Container;

// 1. Create migration manager instance.
$migration_manager = new MigrationManager(
	'/path/to/migrations', // Directory containing migrations.
	new Container() // Anything implementing "ArrayAccess".
);

// 2. Register migration runners.
$migration_manager->registerMigrationRunner(new SqlMigrationRunner());
$migration_manager->registerMigrationRunner(new PhpMigrationRunner());
```

### Creating new migration

[](#creating-new-migration)

The following code will create `YYYYMMDD_HHMM_name.ext` migration file in configured migration folder and return it's name.

```
use ConsoleHelpers\DatabaseMigration\MigrationManager;

$migration_name = $migration_manager->createMigration(
	'example_migration', // any valid filename
	'sql' // 'php' or 'sql' (comes from migration runner)
);
```

As a result:

- the `/path/to/migrations/20160519_2155_example_migration.sql` file would be created
- the `20160519_2155_example_migration.sql` would be returned to `$migration_name` variable

#### Migration Templates

[](#migration-templates)

**SQL:**

Empty file.

**PHP:**

```
