sylius-labs/doctrine-migrations-extra-bundle
Symfony bundle extending DoctrineMigrationsBundle with container-aware migration instantiation and topological sorting of migrations across multiple namespaces/bundles. Configure migration dependencies to ensure predictable, correct execution order in apps or bundles.
Adding a topological sorter and container injection to DoctrineMigrationsBundle.
composer require sylius-labs/doctrine-migrations-extra-bundle
config/bundles.php:return [
// ...
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
];
config/packages/doctrine_migrations.yaml:doctrine_migrations:
services:
'Doctrine\Migrations\Version\MigrationFactory': 'SyliusLabs\DoctrineMigrationsExtraBundle\Factory\ContainerAwareVersionFactory'
'Doctrine\Migrations\Version\Comparator': 'SyliusLabs\DoctrineMigrationsExtraBundle\Comparator\TopologicalVersionComparator'
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\MigrationsCommonPlugin\MigrationsPluginDependingOnCommonPlugin\MigrationsPluginDependingOnCore\MigrationsIf 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'],
],
]);
}
}
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
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.
This extension is completely free and released under permissive MIT license.
It is originally created by Kamil Kokot. See the list of all contributors.
How can I help you explore Laravel packages today?