sylius-labs / doctrine-migrations-extra-bundle
v0.2.2
2024-07-29 15:10 UTC
Requires
- php: ^8.1
- doctrine/doctrine-migrations-bundle: ^3.0
- doctrine/migrations: ^3.0
- marcj/topsort: ^1.1
- symfony/framework-bundle: ^5.4 || ^6.4 || ^7.0
Requires (Dev)
README
DoctrineMigrationsExtraBundle
向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迁移服务
doctrine_migrations: services: 'Doctrine\Migrations\Version\MigrationFactory': 'SyliusLabs\DoctrineMigrationsExtraBundle\Factory\ContainerAwareVersionFactory' 'Doctrine\Migrations\Version\Comparator': 'SyliusLabs\DoctrineMigrationsExtraBundle\Comparator\TopologicalVersionComparator'
使用方法
在应用程序中
为了定义迁移的拓扑,请在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']
以下配置将导致以下顺序
Core\Migrations
CommonPlugin\Migrations
PluginDependingOnCommonPlugin\Migrations
PluginDependingOnCore\Migrations
在捆绑包中
如果您想使您的捆绑包定义其对自身的依赖,请在捆绑包的扩展中添加配置
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'], ], ]); } }
生成新的差异
由于此捆绑包将动态更改Doctrine迁移的配置,您可能需要指定自己的命名空间,例如
# 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': ~
之后,您将能够通过调用
bin/console doctrine:migrations:diff --namespace=App\\Migrations
版本和发布周期
此软件包遵循语义版本。
尚未计划发布下一个主要版本。根据需要发布次要和修补程序版本。
仅对最近的次要版本提供错误修复。自下一个次要版本发布以来,将提供一年的安全修复。
许可证
此扩展完全免费,并按照宽松的MIT许可证发布。
作者
最初由Kamil Kokot创建。查看所有贡献者的列表。