PHPackages                             knplabs/migration-service-provider - 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. knplabs/migration-service-provider

AbandonedArchivedLibrary

knplabs/migration-service-provider
==================================

Doctrine migration service provider for Silex

166.5k12[2 issues](https://github.com/KnpLabs/MigrationServiceProvider/issues)[1 PRs](https://github.com/KnpLabs/MigrationServiceProvider/pulls)PHP

Since Sep 23Pushed 3y ago27 watchersCompare

[ Source](https://github.com/KnpLabs/MigrationServiceProvider)[ Packagist](https://packagist.org/packages/knplabs/migration-service-provider)[ RSS](/packages/knplabs-migration-service-provider/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

DEPRECATED
==========

[](#deprecated)

Unfortunately we decided to not maintain this project anymore ([see why](https://knplabs.com/en/blog/news-for-our-foss-projects-maintenance)). If you want to mark another package as a replacement for this one please send an email to .

Migrations
==========

[](#migrations)

This is a simple homebrew schema migration system for silex and doctrine.

Install
-------

[](#install)

As usual, just include `knplabs/migration-service-provider` in your `composer.json` (don't tell me you don't have one, it's 2012 already), and register the service. You will have to pass the `migration.path` option, which should contain the path to your migrations files:

```
$app->register(new \Knp\Provider\MigrationServiceProvider(), array(
    'migration.path' => __DIR__.'/../src/Resources/migration'
));
```

Enough small talk, I want to write migrations!
----------------------------------------------

[](#enough-small-talk-i-want-to-write-migrations)

And I am too lazy to write a comprehensive documentation right now, so you will have to rely on two external resources:

1. [The marketplace's migrations](https://github.com/KnpLabs/marketplace/tree/master/src/Resources/migrations)
2. [The official documentation for Doctrine's DBAL Schema Manager](http://readthedocs.org/docs/doctrine-dbal/en/latest/reference/schema-manager.html)

Running migrations
------------------

[](#running-migrations)

There are two ways of running migrations

### Using the `before` handler

[](#using-the-before-handler)

If you pass a `migration.register_before_handler` (set to `true`) when registering the service, then a `before` handler will be registered for migration to be run. It means that the migration manager will be run for each hit to your application.

You might want to enable this behavior for development mode, but please don't do that in production!

### Using the `knp:migration:migrate` command

[](#using-the-knpmigrationmigrate-command)

If you installed the console service provider right, you can use the `knp:migration:migrate` command.

Writing migrations
------------------

[](#writing-migrations)

A migration consist of a single file, holding a migration class. By design, the migration file must be named something like `_Migration.php` and located in `src/Resources/migrations`, and the class `Migration`. For example, if your migration adds a `bar` field to the `foo` table, and is the 5th migration of your schema, you should name your file `05_FooBarMigration.php`, and the class would be named `FooBarMigration`.

In addition to these naming conventions, your migration class must extends `Knp\Migration\AbstractMigration`, which provides a few helping method such as `getVersion` and default implementations for migration methods.

The migration methods consist of 4 methods:

- `schemaUp`
- `schemaDown`
- `appUp`
- `appDown`

The names are pretty self-explanatory. Each `schema*` method is fed a `Doctrine\DBAL\Schema\Schema` instance of which you're expected to work to add, remove or modify fields and/or tables. The `app*` method are given a `Silex\Application` instance, actually your very application. You can see an example of useful `appUp` migration in the marketplace's [CommentMarkdownCacheMigration](https://github.com/knplabs/marketplace/blob/master/src/Resources/migrations/04_CommentMarkdownCacheMigration.php).

Migration infos
---------------

[](#migration-infos)

There's one last method you should know about: `getMigrationInfo`. This method should return a self-explanatory description of the migration (it is optional though, and you can skip its implementation). When a migration implementing the `getMigrationInfo` method is run, and if you use twig, a global variable is set in your twig environment containing an array of all run migration informations.

You can then use it with something like that:

```
      {% if migration_infos is defined %}

          Some migrations have been run:

          {% for info in migration_infos %}
            {{ info }}
          {% endfor %}

      {% endif %}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 52.9% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10758?v=4)[Geoffrey Bachelet](/maintainers/ubermuda)[@ubermuda](https://github.com/ubermuda)

---

Top Contributors

[![ubermuda](https://avatars.githubusercontent.com/u/10758?v=4)](https://github.com/ubermuda "ubermuda (9 commits)")[![maerlyn](https://avatars.githubusercontent.com/u/21580?v=4)](https://github.com/maerlyn "maerlyn (1 commits)")[![marchenko1985](https://avatars.githubusercontent.com/u/88868?v=4)](https://github.com/marchenko1985 "marchenko1985 (1 commits)")[![maximkou](https://avatars.githubusercontent.com/u/2118695?v=4)](https://github.com/maximkou "maximkou (1 commits)")[![Nek-](https://avatars.githubusercontent.com/u/972456?v=4)](https://github.com/Nek- "Nek- (1 commits)")[![PedroTroller](https://avatars.githubusercontent.com/u/1766827?v=4)](https://github.com/PedroTroller "PedroTroller (1 commits)")[![rmasters](https://avatars.githubusercontent.com/u/34284?v=4)](https://github.com/rmasters "rmasters (1 commits)")[![docteurklein](https://avatars.githubusercontent.com/u/109846?v=4)](https://github.com/docteurklein "docteurklein (1 commits)")[![weaverryan](https://avatars.githubusercontent.com/u/121003?v=4)](https://github.com/weaverryan "weaverryan (1 commits)")

### Embed Badge

![Health badge](/badges/knplabs-migration-service-provider/health.svg)

```
[![Health](https://phpackages.com/badges/knplabs-migration-service-provider/health.svg)](https://phpackages.com/packages/knplabs-migration-service-provider)
```

PHPackages © 2026

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