sylius-labs/doctrine-migrations-extra-bundle

v0.2.0 2022-09-05 07:43 UTC

This package is auto-updated.

Last update: 2024-04-05 18:19:00 UTC


README

68747470733a2f2f64656d6f2e73796c6975732e636f6d2f6173736574732f73686f702f696d672f6c6f676f2e706e67

DoctrineMigrationsExtraBundle

Adding a topological sorter and container injection to DoctrineMigrationsBundle.

Installation

  1. Require this package in your project:
composer require sylius-labs/doctrine-migrations-extra-bundle
  1. Add this bundle to config/bundles.php:
return [
    // ...
    SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
];
  1. Replace original Doctrine migrations services with the ones from this bundle by adding the following config in config/packages/doctrine_migrations.yaml:
doctrine_migrations:
    services:
        'Doctrine\Migrations\Version\MigrationFactory': 'SyliusLabs\DoctrineMigrationsExtraBundle\Factory\ContainerAwareVersionFactory'
        'Doctrine\Migrations\Version\Comparator': 'SyliusLabs\DoctrineMigrationsExtraBundle\Comparator\TopologicalVersionComparator'

Usage

In an application

In order to define the topology of migrations, configure it in config/packages/sylius_labs_doctrine_migrations_extra.yaml:

sylius_labs_doctrine_migrations_extra:
    migrations:
        'Core\Migrations': ~
        'PluginDependingOnCommonPlugin\Migrations': ['Core\Migrations', 'CommonPlugin\Migrations']
        'CommonPlugin\Migrations': ['Core\Migrations']
        'PluginDependingOnCore\Migrations': ['Core\Migrations']

The following configuration will result in the following order:

  • Core\Migrations
  • CommonPlugin\Migrations
  • PluginDependingOnCommonPlugin\Migrations
  • PluginDependingOnCore\Migrations

In a bundle

If you want to make your bundle define its dependencies on it own, prepend the configuration in your bundle's extension:

use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;

final class AcmeExtension extends Extension implements PrependExtensionInterface
{
    // ...

    public function prepend(ContainerBuilder $container): void
    {
        if (!$container->hasExtension('doctrine_migrations') || !$container->hasExtension('sylius_labs_doctrine_migrations_extra')) {
            return;
        }

        $container->prependExtensionConfig('doctrine_migrations', [
            'migrations_paths' => [
                'Acme\AcmeBundle\Migrations' => '@AcmeBundle/Migrations',
            ],
        ]);

        $container->prependExtensionConfig('sylius_labs_doctrine_migrations_extra', [
            'migrations' => [
                'Acme\AcmeBundle\Migrations' => ['Core\Migrations'],
            ],
        ]);
    }
}

Generating new diff

Cause this bundle will dynamically change the configuration of Doctrine Migrations, you may need to specify your own namespace like:

# config/packages/doctrine_migrations.yaml
doctrine_migrations:
  migrations_paths:
    'App\Migrations': "%kernel.project_dir%/src/Migrations"

# config/packages/sylius_labs_doctrine_migrations_extra.yaml
sylius_labs_doctrine_migrations_extra:
  migrations:
    'App\Migrations': ~

After that you will be able to generate again your own migration by calling:

bin/console doctrine:migrations:diff --namespace=App\\Migrations

Versioning and release cycle

This package follows semantic versioning.

Next major releases are not planned yet. Minor and patch releases will be published as needed.

Bug fixes will be provided only for the most recent minor release. Security fixes will be provided for one year since the release of subsequent minor release.

License

This extension is completely free and released under permissive MIT license.

Authors

It is originally created by Kamil Kokot. See the list of all contributors.