Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/e282486518/yii2-console-migration
yii2命令行中使用migration备份和还原数据库
https://github.com/e282486518/yii2-console-migration
migration yii2 yii2-migration
Last synced: about 2 months ago
JSON representation
yii2命令行中使用migration备份和还原数据库
- Host: GitHub
- URL: https://github.com/e282486518/yii2-console-migration
- Owner: e282486518
- Created: 2016-11-18T12:26:47.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-08-09T03:20:58.000Z (over 5 years ago)
- Last Synced: 2024-09-18T00:07:23.599Z (4 months ago)
- Topics: migration, yii2, yii2-migration
- Language: PHP
- Size: 23.4 KB
- Stars: 36
- Watchers: 5
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
注意:如果你使用的是php7.2,那么yii必须使用v2.0.15.1以上,因为yii2核心类Object和php7.2的保留类Object冲突。
```php
use yii\base\Object // PHP7.1以及之前版本
use yii\base\BaseObject // PHP7.2
```yii2使用migration备份和还原数据库
===========================
yii2使用migration备份和还原数据库,最初只想做一个在命令行中备份的功能,后来将类重组了,增加了其他扩展使用方法。安装 Installation
------------安装此扩展的首选方式是通过 [composer](http://getcomposer.org/download/).
运行
```
composer require e282486518/yii2-console-migration "@dev"
```或者添加
```
"e282486518/yii2-console-migration": "*"
```到 `composer.json` 文件的对应地方.
命令行中备份数据表:
-----在```console\config\main.php```中添加 :
```php
'controllerMap' => [
'migrate' => [
'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```中加入下面的代码:
```php
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```
或者使用一下代码:
```php
$migrate = Yii::createObject([
'class' => 'e282486518\migration\components\MigrateCreate',
'migrationPath' => $this->migrationPath
]);
$migrate->create($table);
```