Giter Club home page Giter Club logo

yii2-console-migration's Introduction

yii2使用migration备份和还原数据库

yii2使用migration备份和还原数据库,最初只想做一个在命令行中备份的功能,后来将类重组了,增加了其他扩展使用方法。

安装 Installation

安装此扩展的首选方式是通过 composer.

运行

composer require --prefer-dist e282486518/yii2-console-migration "*"

或者添加

"e282486518/yii2-console-migration": "*"

composer.json 文件的对应地方.

命令行中备份数据表:

console\config\main.php中添加 :

'controllerMap' => [
    'migrates' => [
        'class' => 'e282486518\migration\ConsoleController',
    ],
],

在命令行中使用方式:

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

php ./yii migrate/up #恢复全部表

在后台中备份数据表:

在后台的控制器中,例如PublicController中加入下面的代码:

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

在后台中发送一个ajax请求到/admin/public/backup?tables=yii2_ad,yii2_admin即可。

其他使用方法:

对于想做更多扩展的朋友,可以直接继承e282486518\migration\components\MigrateCreate

或者使用一下代码:

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

yii2-console-migration's People

Contributors

e282486518 avatar lxiangcn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.