PHP code example of rmrevin / yii2-power-migration

1. Go to this page and download the library: Download rmrevin/yii2-power-migration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rmrevin / yii2-power-migration example snippets


<?
return [
	// ...
	'controllerMap' => [
		// ...
		'migrate' => [
            'class' => yii\console\controllers\MigrateController::class,
            'templateFile' => '@vendor/rmrevin/yii2-power-migration/template.php',
        ],
	],
	// ...
];

<?

use yii\db\Schema;
use rmrevin\yii\db\migration;

class m140317_055355_file extends migration\PowerMigration
{

    public function instructions()
    {
        return [
            'createTableFile',
            'createTableFileLink',
        ];
    }

    public function createTableFile_up()
    {
        $this->createTable('{{%file}}', [
            'id' => Schema::TYPE_PK,
            'mime' => Schema::TYPE_STRING . ' NOT NULL',
            'size' => Schema::TYPE_BIGINT . ' NOT NULL DEFAULT 0',
            'name' => Schema::TYPE_STRING . ' NOT NULL',
            'origin_name' => Schema::TYPE_STRING . ' NOT NULL',
            'sha1' => Schema::TYPE_STRING . '(40) NOT NULL',
            'image_bad' => Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 0',
        ]);
    }

    public function createTableFile_down()
    {
        $this->dropTable('{{%file}}');
    }
    
    public function createTableFileLink_up()
    {
        $this->createTable('{{%file_link}}', [
            'file_id' => Schema::TYPE_PK,
            'url' => Schema::TYPE_STRING . ' NOT NULL',
        ]);
    }

    public function createTableFileLink_down()
    {
        $this->dropTable('{{%file_link}}');
    }
}