PHPackages                             hjp1011/yii2-console-migration - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. hjp1011/yii2-console-migration

ActiveYii2-extension[Database &amp; ORM](/categories/database)

hjp1011/yii2-console-migration
==============================

yii2命令行中使用migration备份和还原数据库

1.0.1(4y ago)05651Apache-2.0PHP

Since Dec 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/hjp1011/yii2-console-migration)[ Packagist](https://packagist.org/packages/hjp1011/yii2-console-migration)[ RSS](/packages/hjp1011-yii2-console-migration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

Introduction
------------

[](#introduction)

Yii2 uses Migration to back up and restore the database, adding other extended usage methods.

Notice：
-------

[](#notice)

If you are using PHP7.2, then yII must use v2.0.15.1 or higher, because the yii2 core class Object conflicts with the PHP7.2 reserved class Object.

[![Latest Stable Version](https://camo.githubusercontent.com/9f75489a3a09e6024ecc723947a57a9a108dc9e6992a0811288ac9938b96f9cc/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d636f6e736f6c652d6d6967726174696f6e2f76)](https://packagist.org/packages/hjp1011/yii2-console-migration) [![Total Downloads](https://camo.githubusercontent.com/6bc557c4a1418c97dfb1315cb12b22e317491d1f70eb16956a3133cd431154b8/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d636f6e736f6c652d6d6967726174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/hjp1011/yii2-console-migration) [![Latest Unstable Version](https://camo.githubusercontent.com/fe9030529531bc79e8a045fb1cfd92c1b9568e7b3ff35a9f0f5b28e68cc7657a/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d636f6e736f6c652d6d6967726174696f6e2f762f756e737461626c65)](https://packagist.org/packages/hjp1011/yii2-console-migration) [![License](https://camo.githubusercontent.com/8c2b0fb3c2357c5db3e8db903bc7bf9a7bc5360fe66829411dfe794caa15d159/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d636f6e736f6c652d6d6967726174696f6e2f6c6963656e7365)](https://packagist.org/packages/hjp1011/yii2-console-migration) [![PHP Version Require](https://camo.githubusercontent.com/a787617437d2f96d705491ce321b14251b49d380166ba2c254c489928ac21056/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d636f6e736f6c652d6d6967726174696f6e2f726571756972652f706870)](https://packagist.org/packages/hjp1011/yii2-console-migration)

```
use yii\base\Object // PHP7.1 and previous versions
use yii\base\BaseObject // PHP7.2
```

Installation
------------

[](#installation)

The preferred way to install this extension is through \[composer\] ().

Run

```
composer require hjp1011/yii2-console-migration "*"

```

Or add

```
"hjp1011/yii2-console-migration": "*"

```

To the corresponding location of the 'composer. Json' file.

usage
-----

[](#usage)

Backup table in command line:
-----------------------------

[](#backup-table-in-command-line)

in`console\config\main.php` add :

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

Use on the command line:

```
php ./yii migrate/backup all #Backup all tables
php ./yii migrate/backup table1,table2,table3... #Backup multiple tables
php ./yii migrate/backup table1 #Back up a table

php ./yii migrate/up #Restore all tables

```

Back up tables in the background:
---------------------------------

[](#back-up-tables-in-the-background)

Add the following code to a background controller, such as PublicController:

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

Send an Ajax request to`/admin/public/backup?tables=yii2_ad,yii2_admin`。

Other usage:
------------

[](#other-usage)

For friends who want to do more extensions, you can inherit directly `yiiframe\migration\components\MigrateCreate`

Or use the following code:

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1612d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3722805f06e7a49dc67f3ff1c7fac9239b9028169f0aa129b56f4ba641a8d14c?d=identicon)[YiiFrame](/maintainers/YiiFrame)

---

Top Contributors

[![hjp1011](https://avatars.githubusercontent.com/u/15049554?v=4)](https://github.com/hjp1011 "hjp1011 (4 commits)")

---

Tags

consolemigrationyii2

### Embed Badge

![Health badge](/badges/hjp1011-yii2-console-migration/health.svg)

```
[![Health](https://phpackages.com/badges/hjp1011-yii2-console-migration/health.svg)](https://phpackages.com/packages/hjp1011-yii2-console-migration)
```

###  Alternatives

[bizley/migration

Migration generator for Yii 2.

297374.3k11](/packages/bizley-migration)[dmstr/yii2-migrate-command

Console Migration Command with multiple paths/aliases support

31295.5k6](/packages/dmstr-yii2-migrate-command)[e282486518/yii2-console-migration

yii2命令行中使用migration备份和还原数据库

388.1k4](/packages/e282486518-yii2-console-migration)[c006/yii2-migration-utility

Automatically writes the create tables for migrations or create tables in general

63160.6k1](/packages/c006-yii2-migration-utility)[tmukherjee13/yii2-reverse-migration

Generate working migration classes from existing Database

2321.5k](/packages/tmukherjee13-yii2-reverse-migration)[hzhihua/yii2-dump

Generate the schema from an existing database

1828.5k1](/packages/hzhihua-yii2-dump)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
