phisys / migrations-bundle
phpmig 的 Symfony 框架集成包
v1.0.0
2021-04-27 07:07 UTC
Requires
- php: ^7.4|^8.0
- davedevelopment/phpmig: ^1.7
- symfony/console: 4.*|5.*
- symfony/dependency-injection: 4.*|5.*
- symfony/http-kernel: 4.*|5.*
Suggests
- ext-mongodb: To be able to create migrations for MongoDB using provided MongoDBDriverManager
- doctrine/dbal: To be able to create migrations using Doctrine DBAL
This package is auto-updated.
Last update: 2024-09-28 15:18:39 UTC
README
对 davedevelopment/phpmig 的 Symfony 框架集成
设置
# config/bundles.php return [ PhiSYS\MigrationsBundle\PhiSYSMigrationsBundle::class => ['dev' => true, 'test' => true], ];
# services.yaml parameters: phisys.migrations.migrations_directory: '%kernel.project_dir%/migrations/postgresql/' phisys.migrations.migration_template: '%kernel.project_dir%/vendor/phisys/migrations-bundle/src/Resources/templates/dbalSql.php.twig' phisys.migrations.control_table: 'serviceschema.migrations' services: PhiSYS\MigrationsBundle\Infrastructure\Service\Phpmig\Adapter\Adapter: class: PhiSYS\MigrationsBundle\Infrastructure\Service\Phpmig\Adapter\DbalAdapter public: false autoconfigure: true arguments: $connection: '@connection.dbal.myservice' # Doctrine DBAL Connection $tableName: '%phisys.migrations.control_table%' PhiSYS\MigrationsBundle\Infrastructure\Service\Phpmig\ConfigurationContainer: public: true class: PhiSYS\MigrationsBundle\Infrastructure\Service\Phpmig\ConfigurationContainer autoconfigure: true factory: PhiSYS\MigrationsBundle\Infrastructure\Service\Phpmig\ConfigurationContainer::from arguments: $adapter: '@PhiSYS\MigrationsBundle\Infrastructure\Service\Phpmig\Adapter\Adapter' $directory: '%phisys.migrations.migrations_directory%' $template: '%phisys.migrations.migration_template%'
使用
- 初始化控制表(只需一次)
$ console migrations:init
- 查看当前迁移状态
要在需要非零返回值来表示错误的批处理脚本中使用$ console migrations:status
$ console migrations:check
- 从模板生成新的迁移
$ console migrations:generate ThisIsTheMigrationSubject
- 执行待处理的迁移
执行到指定迁移ID(在指定迁移ID处停止)$ console migrations:migrate
$ console migrations:migrate --target 20201014114643
- 回滚最后一个迁移
要回滚到指定的迁移ID,使用$ console migrations:rollback
$ console migrations:rollback --target 20201014114643
- 向上执行迁移ID
$ console migrations:up 20201014114643
- 向下执行迁移ID
要重新执行(向下和向上)已迁移的ID,可以使用单个命令$ console migrations:down 20201014114643
$ console migrations:redo 20201014114643