vados / phalcon-migration-runner
Phalcon 框架的简单迁移运行器
0.1
2019-02-25 18:05 UTC
Requires
- php: >=7.1.0
- ext-phalcon: >=3.2
Requires (Dev)
- phalcon/ide-stubs: v3.2.1
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-26 06:44:49 UTC
README
支持 PHP 7.1+
用法
您可以使用 'migration_runner' 命令来创建和应用到数据库中的迁移,或者回滚迁移。
./vendor/bin/migration_runner <method>
默认情况下,运行器调用 'help' 方法。
可用方法
- help - 显示帮助信息
- create {name} - 创建新的迁移
- up {runCount=0} - 应用新迁移
- down {runCount=1} - 回滚一些迁移
在您的迁移中,您应该使用通过 'getDbConnection' 方法提供的 Phalcon Pdo 适配器。您可以在 Phalcon 文档 中找到 API 定义。
public function up(): bool { $this->getDbConnection()->createTable('foo', null, [ 'columns' => [ new \Phalcon\Db\Column('bar', [ 'type' => \Phalcon\Db\Column::TYPE_INTEGER ]) ] ]); return true; }
示例
创建迁移(对于第一次运行,运行器将创建配置)
$ ./vendor/bin/migration_runner create new_migration Enter database adapter (default: sqlite): sqlite Enter database name (default: phalcon): test.db Config generated in /my_project/migration_runner.config.php Migration /my_project/migrations/m1522260172_new_migration.php created!
描述您的迁移
<?php use Phalcon\Db\Column; use Vados\MigrationRunner\migration\Migration; class m1522260172_new_migration extends Migration { public function up(): bool { $this->getDbConnection()->createTable('foo', null, [ 'columns' => [ new Column('bar', [ 'type' => Column::TYPE_INTEGER ]) ] ]); return true; } public function down(): bool { $this->getDbConnection()->dropTable('foo'); return true; } }
应用您的迁移
$ ./migration_runner up m1522260172_new_migration.php Apply the above migrations? (yes|no) [yes]: yes Migration m1522260172_new_migration.php: true
安装
使用 composer 进行安装
composer require vados/phalcon-migration-runner
贡献指南
- 编写测试
- 代码审查
- 指导原则