execut/yii2-migration
Composer 安装命令:
composer require execut/yii2-migration
包简介
Yii2 helper to simplify of writing migration
关键字:
README 文档
README
This is a typical migration for yii2:
public function safeUp() { $this->createTable('characteristics_units', [ 'id' => $this->primaryKey(), 'name' => $this->string()->notNull(), 'short_name' => $this->string()->notNull(), 'created' => $this->dateTime()->notNull()->defaultExpression('now()'), 'updated' => $this->dateTime(), ]); $this->createTable('characteristics', [ 'id' => $this->primaryKey(), 'characteristics_unit_id' => $this->integer()->notNull(), 'name' => $this->string()->notNull(), 'created' => $this->dateTime()->notNull()->defaultExpression('now()'), 'updated' => $this->dateTime(), ]); $this->addForeignKey('characteristics_unit_id_characteristics_fk', 'characteristics', 'characteristics_unit_id', 'characteristics_units', 'id'); } public function safeDown() { $this->dropTable('characteristics'); $this->dropTable('characteristics_units'); }
Why write more? If you use execut yii2-migration helper, you can write it faster and more compact:
public function initInverter(\execut\yii\migration\Inverter $i) { $i->table('characteristics')->create(array_merge($this->defaultColumns(), [ 'name' => $this->string()->notNull(), 'short_name' => $this->string()->notNull(), ])); $i->table('characteristics_units')->create(array_merge($this->defaultColumns(), [ 'name' => $this->string()->notNull(), ]))->addForeignColumn('characteristics'); }
Installation
The preferred way to install this extension is through composer.
Install
Either run
$ php composer.phar require execut/yii2-migration "dev-master"
or add
"execut/yii2-migration": "dev-master"
to the require section of your composer.json file.
Usage
To use yii2 migration, simply expand the migration class from the execut\yii\migration\Migration class and override the abstract method:
public function initInverter(\execut\yii\migration\Inverter $i) { }
$i has all the methods that normal migration has, but allows you to write actions up and down at a time.
To permanently do not rewrite the migration, you can define a new template for the yii migrate\create command.
'controllerMap' => [ 'migrate' => [ 'templateFile' => '@vendor/execut/yii2-migration/views/template.php', ],
Supported databases
Currently only supported PostgreSQL and MySQL. Also you can use BDR plugin for PostgreSQL.
统计信息
- 总下载量: 761
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2016-12-05