2017 © Pedro Peláez
 

library migrate-bundle

Provides an initial scaffolding for building migrations

image

aureka/migrate-bundle

Provides an initial scaffolding for building migrations

  • Thursday, June 19, 2014
  • by carlescliment
  • Repository
  • 6 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

MigrateBundle

Build Status, (*1)

Provides a little scaffolding for migrations., (*2)

Configuration

1.- Add the bundle to your composer.json file and execute composer update., (*3)

{
    "require": {
        "aureka/migrate-bundle": "*"
    }
}

2.- Modify your AppKernel.php, (*4)

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Aureka\MigrateBundle\AurekaMigrateBundle(),
            );
        // ...
    }
}

3.- Configure your legacy database in config.yml, (*5)

aureka_migrate: database: connector: 'mysqli' host: 'localhost' user: 'root' password: '123' database: 'my_database', (*6)

Adding migrators

It is time for you to add your custom migrators. Declare each migrator as a service tagged by aureka_migrate.migrator., (*7)

services:
    your_migration_bundle.users_migrator:
            class: Your\MigrationBundle\Migrator\UsersMigrator
            arguments: ['@aureka_migrate.legacy_connection', '@doctrine.orm.entity_manager']
            tags:
                - { name: aureka_migrate.migrator }

A migrator could be something like this:, (*8)


use Doctrine\Common\Persistence\ObjectManager; use Aureka\MigrateBundle\Migrator\Migrator, Aureka\MigrateBundle\Service\Database\Connection; class UsersMigrator implements Migrator { private $legacyConnection; private $om; public function __construct(Connection $legacyConnection, ObjectManager $om) { $this->legacyConnection = $legacyConnection; $this->om = $om; } public function prepare() { // Do whatever you need to prepare the migration, like cleaning the destination tables return $this; } public function migrate() { $users = $this->legacyConnection->fetchAll('SELECT * FROM users'); foreach ($users as $legacy_user) { $user = new User; $user->name = $legacy_user['username']; // ... $this->om->persist($user); } $this->om->flush(); return $this; }

Running migrations

Now you can execute the following command:, (*9)

php app/console aureka_migrate:migrate

The Versions

19/06 2014

dev-master

9999999-dev

Provides an initial scaffolding for building migrations

  Sources   Download

GPL2

The Development Requires

by Carles Climent