PHP Classes

File: gii/default_bymodel/migration.php

Recommend this page to a friend!
  Classes of Insolita   YII2 Migrik   gii/default_bymodel/migration.php   Download  
File: gii/default_bymodel/migration.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: YII2 Migrik
Create migration files for applications using YII2
Author: By
Last change:
Date: 4 months ago
Size: 911 bytes
 

Contents

Class file image Download
<?php
/**
 * This view is used by console/controllers/MigrateController.php
 * The following variables are available in this view:
 */
/** @var $migrationName string the new migration class name
 * @var $table string table_name
 * @var array $columns
 * @var string $db
 * @var string $tableOptions
 */

echo "<?php\n";
?>

use yii\db\Schema;
use yii\db\Migration;

class <?= $migrationName ?> extends Migration
{

    public function init()
    {
        $this->db = '<?=$db?>';
        parent::init();
    }

    public function safeUp()
    {
        $tableOptions = '<?=$tableOptions?>';

        $this->createTable(
            '<?= $table?>',
            [
<?php foreach ($columns as $name => $data) :?>
'<?=$name?>'=> <?=$data;?>,
<?php endforeach;?>
],$tableOptions
        );
    }

    public function safeDown()
    {
        $this->dropTable('<?= $table?>');
    }
}