clear01 / doctrine-migrations
Doctrine Migrations 到 Nette 的实现
v4.4.0
2019-10-02 11:03 UTC
Requires
- php: ^7.0
- arachne/event-dispatcher: ^0.1
- doctrine/migrations: ^1.4
- nette/di: ^2.4
- symfony/console: ^3.1
- symfony/event-dispatcher: ^3.1
Requires (Dev)
- kdyby/console: ^2.6
- kdyby/doctrine: ^3.1
- kdyby/events: ^3.0
- nette/bootstrap: ^2.4
- nette/reflection: ^2.4
- phpunit/phpunit: ^5.6
- tracy/tracy: ^2.4
- zenify/coding-standard: ^4.0
- dev-master
- v4.4.0
- v4.3.1
- v4.3
- v4.2
- v4.1
- v3.0.0
- v2.3.5
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.0
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.0
- dev-BOTKYDETEM-65
- dev-MAS-582
- dev-MAS-641
- dev-MAS-648
- dev-MAS-651
- dev-MAS-656
- dev-MAS-664
- dev-MAS-681
- dev-MAS-707
- dev-MAS-762
- dev-MAS-785
- dev-MAS-823
- dev-MAS-826
- dev-MAS-896
- dev-ECOM-62
This package is auto-updated.
Last update: 2024-09-10 20:14:59 UTC
README
Doctrine Migrations 到 Nette 的实现。
安装
composer require zenify/doctrine-migrations
在 config.neon 中注册扩展
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
配置
config.neon 的默认值
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
使用方法
打开您的 CLI 并运行命令(基于 Kdyby\Console 集成)
php www/index.php
然后您应该能看到所有可用的命令
将更改迁移到数据库
如果您想将现有的迁移应用到数据库中,只需运行迁移命令
php www/index.php migrations:migrate
如果您迷路了,只需使用 -h 选项获取帮助
php www/index.php migrations:migrate -h
创建新的迁移
要创建一个新的空迁移,只需运行
php www/index.php migrations:generate
新的空迁移将创建在您的迁移目录中。您可以在那里添加您的 SQL。
将新角色 "superadmin" 添加到 user_role 表的迁移将看起来像这样
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);"); } }
就这么简单!
有关进一步使用,请参阅Symfony bundle 中的文档。
功能
迁移组织
如果您在一个目录中有一个超过 100 个迁移,可能会变得杂乱。幸运的是,Doctrine 迁移可以根据年份或年份和月份组织您的迁移到目录。您可以在您的 config.neon 中配置它(见上面)。
/migrations/2015/11
- VersionXXX.php
/migrations/2015/12
- VersionYYY.php
/migrations/2016/01
- VersionZZZ.php
注入迁移
注意:这并不是最佳实践,因此只有在没有其他方法的情况下才尝试使用它。
namespace Migrations; final class Version20140801152432 extends AbstractMigration { /** * @inject * @var Doctrine\ORM\EntityManagerInterface */ public $entityManager; public function up(Schema $schema) { // ... } // ... }
测试
composer check-cs vendor/bin/phpunit
贡献
规则很简单
- 新功能需要测试
- 所有测试必须通过
- 每个 PR 一个功能
我们将很高兴合并您的功能!
