2017 © Pedro Peláez
 

library doctrine-migrations

Implementation of Doctrine Migrations to Nette

image

zenify/doctrine-migrations

Implementation of Doctrine Migrations to Nette

  • PHP
  • 6 Dependents
  • 3 Suggesters
  • 12 Forks
  • 0 Open issues
  • 33 Versions
  • 4 % Grown

The README.md

Doctrine Migrations

Build Status Quality Score Code Coverage Downloads this Month Latest stable, (*1)

Implementation of Doctrine\Migrations to Nette., (*2)

Install

composer require zenify/doctrine-migrations

Register extensions in config.neon:, (*3)

extensions:
    - Arachne\ContainerAdapter\DI\ContainerAdapterExtension
    - Arachne\EventDispatcher\DI\EventDispatcherExtension
    migrations: Zenify\DoctrineMigrations\DI\MigrationsExtension

    # Kdyby\Doctrine or another Doctrine integration
    doctrine: Kdyby\Doctrine\DI\OrmExtension

Configuration

config.neon with default values, (*4)

migrations:
    table: doctrine_migrations # database table for applied migrations
    column: version # database column for applied migrations
    directory: %appDir%/../migrations # directory, where all migrations are stored
    namespace: Migrations # namespace of migration classes
    codingStandard: tabs # or "spaces", coding style for generated classes
    versionsOrganization: null # null, "year" or "year_and_month", organizes migrations to subdirectories

Usage

Open your CLI and run command (based on Kdyby\Console integration):, (*5)

php www/index.php

And then you should see all available commands:, (*6)

CLI commands, (*7)

Migrate changes to database

If you want to migrate existing migration to your database, just run migrate commmand:, (*8)

php www/index.php migrations:migrate

If you get lost, just use -h option for help:, (*9)

php www/index.php migrations:migrate -h

Create new migration

To create new empty migration, just run:, (*10)

php www/index.php migrations:generate

A new empty migration will be created at your migrations directory. You can add your sql there then., (*11)

Migration that would add new role "superadmin" to user_role table would look like this:, (*12)

namespace Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
 * New role "superadmin" added.
 */
final class Version20151015000003 extends AbstractMigration
{

    public function up(Schema $schema)
    {
        $this->addSql("INSERT INTO 'user_role' (id, value, name) VALUES (3, 'superadmin', 'Super Admin')");
    }


    public function down(Schema $schema)
    {
        $this->addSql("DELETE FROM 'user_role' WHERE ('id' = 3);");
    }

}

Simple as that!, (*13)

For further use, please check docs in Symfony bundle., (*14)

Features

Migrations organization

If you have over 100 migrations in one directory, it might get messy. Fortunately doctrine migrations can organize your migrations to directories by year or by year and month. You can configure it in your config.neon (see above)., (*15)

/migrations/2015/11
    - VersionXXX.php
/migrations/2015/12
    - VersionYYY.php
/migrations/2016/01
    - VersionZZZ.php

Injected migrations

Note: this is not really best practise, so try to use it only if there is no other way., (*16)

namespace Migrations;

final class Version20140801152432 extends AbstractMigration
{

    /**
     * @inject
     * @var Doctrine\ORM\EntityManagerInterface
     */
    public $entityManager;


    public function up(Schema $schema)
    {
        // ...
    }

    // ...

}

Testing

composer check-cs
vendor/bin/phpunit

Contributing

Rules are simple:, (*17)

  • new feature needs tests
  • all tests must pass
  • 1 feature per PR

We would be happy to merge your feature then!, (*18)

The Versions

25/08 2014

v0.7.0

0.7.0.0

Implementation of Doctrine Migrations to Nette

  Sources   Download

MIT

The Requires

 

17/08 2014

v0.6.0

0.6.0.0

Implementation of Doctrine Migrations to Nette

  Sources   Download

MIT

The Requires

 

17/08 2014

v0.3.0

0.3.0.0

Implementation of Doctrine Migrations to Nette

  Sources   Download

MIT

The Requires

 

17/08 2014

v0.5.0

0.5.0.0

Implementation of Doctrine Migrations to Nette

  Sources   Download

MIT

The Requires

 

17/08 2014

v0.4.0

0.4.0.0

Implementation of Doctrine Migrations to Nette

  Sources   Download

MIT

The Requires

 

16/08 2014

v0.2.0

0.2.0.0

Implementation of Doctrine Migrations to Nette

  Sources   Download

MIT

The Requires

 

16/08 2014

v0.1.0

0.1.0.0

Implementation of Doctrine Migrations to Nette

  Sources   Download

MIT

The Requires