PHP code example of jianyan74 / yii2-console-migration

1. Go to this page and download the library: Download jianyan74/yii2-console-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/ */

    

jianyan74 / yii2-console-migration example snippets


use yii\base\Object // PHP7.1以及之前版本
use yii\base\BaseObject // PHP7.2

'controllerMap' => [
    'migrate' => [
        'class' => 'jianyan\migration\ConsoleController',
    ],
],

public function actions()
{
    return [
        'backup' => [
            'class' => 'jianyan\migration\WebAction',
            'returnFormat' => 'json',
            'migrationPath' => '@console/migrations'
        ]
    ];
}

$migrate = Yii::createObject([
        'class' => 'jianyan\migration\components\MigrateCreate',
        'migrationPath' => $this->migrationPath
]);
$migrate->create($table);

php ./yii migrate/backup all #备份全部表
php ./yii migrate/backup table1,table2,table3... #备份多张表
php ./yii migrate/backup table1 #备份一张表

php ./yii migrate/up #恢复全部表
/admin/public/backup?tables=yii2_ad,yii2_admin