PHPackages                             imiphp/imi-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. imiphp/imi-migration

ActiveLibrary[Database &amp; ORM](/categories/database)

imiphp/imi-migration
====================

imi 框架数据库迁移组件。imi Migration component.

v2.1.0(2y ago)344GPL-2.0PHP

Since Sep 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/imiphp/imi-migration)[ Packagist](https://packagist.org/packages/imiphp/imi-migration)[ RSS](/packages/imiphp-imi-migration/feed)WikiDiscussions 2.1 Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

imi-migration
=============

[](#imi-migration)

[![Latest Version](https://camo.githubusercontent.com/1e71e29937f11939b85e2d231b56f84e89e0b61f9860259eebbf20f045a3ed1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d697068702f696d692d6d6967726174696f6e2e737667)](https://packagist.org/packages/imiphp/imi-migration)[![Php Version](https://camo.githubusercontent.com/4a5c2ab20974058a8bab53ecb30ac4c2e6bb961df6229b7386fdc097ab53dfa8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e342d627269676874677265656e2e737667)](https://secure.php.net/)[![Swoole Version](https://camo.githubusercontent.com/2b08ceed852c672ccac1ba1e0db0399fd6c269b1f40d58b8d4cf11455a95446d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73776f6f6c652d2533453d342e382e302d627269676874677265656e2e737667)](https://github.com/swoole/swoole-src)[![imi License](https://camo.githubusercontent.com/98bdbfaa35e79370786c656980aab520be3e8af9551d8418a3ca4da1775f84c9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d756c616e50534c253230322e302d627269676874677265656e2e737667)](https://github.com/imiphp/imi-migration/blob/master/LICENSE)

介绍
--

[](#介绍)

此项目是 imi 框架的数据库迁移组件。

> 正在测试阶段，使用时请先确认 SQL 无误后再执行，本项目不对删库删数据负责。

安装
--

[](#安装)

`composer require imiphp/imi-migration:~2.1.0`

使用说明
----

[](#使用说明)

### 模型同步到表结构

[](#模型同步到表结构)

#### 同步表结构

[](#同步表结构)

将数据库中的数据表结构升级为模型中定义的结构。

```
vendor/bin/imi-swoole migration/patch -f
```

#### 生成同步结构 SQL 语句

[](#生成同步结构-sql-语句)

**输出到命令行：**

```
vendor/bin/imi-swoole migration/patch
```

**保存到文件：**

```
vendor/bin/imi-swoole migration/patch -f "文件名"
```

### 数据库迁移

[](#数据库迁移)

#### 配置

[](#配置)

`@app.beans`:

```
[
    \Imi\Migration\Service\MigrationService::class => [
        'handler' => \Imi\Migration\Handler\FileMigrationHandler::class, // 迁移处理器
        'onGenerateModel' => true, // 是否在生成模型时自动生成迁移文件
    ],
]
```

> 上述配置是默认配置，不配置时自动启用。

#### 目录

[](#目录)

`.migration` 是存放数据库迁移文件和版本信息的目录，请勿将 `.migration/version` 提交到版本控制系统。

#### 执行数据库迁移

[](#执行数据库迁移)

**执行前询问：**

```
vendor/bin/imi-swoole migration/migrate
```

**强制执行：**

```
vendor/bin/imi-swoole migration/migrate -f
```

> 请谨慎操作

### 执行数据库回滚

[](#执行数据库回滚)

**执行前询问：**

```
vendor/bin/imi-swoole migration/rollback
```

**强制执行：**

```
vendor/bin/imi-swoole migration/rollback -f
```

> 请谨慎操作

### 通用参数

[](#通用参数)

#### 指定连接池

[](#指定连接池)

```
vendor/bin/imi-swoole migration/命令 --poolName "连接池名"
```

> 不指定时使用默认连接池

#### 指定连接参数

[](#指定连接参数)

```
vendor/bin/imi-swoole migration/命令 --driver "PdoMysqlDriver" --options "host=127.0.0.1&port=3306&username=root&password=root"
```

免费技术支持
------

[](#免费技术支持)

QQ群：17916227 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq)，如有问题会有人解答和修复。

运行环境
----

[](#运行环境)

- [PHP](https://php.net/) &gt;= 7.4
- [Composer](https://getcomposer.org/) &gt;= 2.0
- [Swoole](https://www.swoole.com/) &gt;= 4.8.0
- [imi](https://www.imiphp.com/) &gt;= 2.1

版权信息
----

[](#版权信息)

`imi-migration` 依赖 [phpmyadmin/sql-parser](https://github.com/phpmyadmin/sql-parser)，所以开源协议受到污染，必须是 GPL-2.0，所有基于本项目的代码都要开源。

建议仅将此组件作为独立工具安装使用，不要在项目中调用此项目中的任意代码，这样就不受开源协议污染了！

捐赠
--

[](#捐赠)

[![](https://camo.githubusercontent.com/24487a1dd6ab2d9c7b7492027024eae97eba149b95eab696a568034005ae335d/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e312f7265732f7061792e706e67)](https://camo.githubusercontent.com/24487a1dd6ab2d9c7b7492027024eae97eba149b95eab696a568034005ae335d/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e312f7265732f7061792e706e67)

开源不求盈利，多少都是心意，生活不易，随缘随缘……

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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 ~141 days

Total

3

Last Release

1051d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f917bb42280d114c53cebadc2942a13ee03abe14971089f88895e266d637169?d=identicon)[Yurunsoft](/maintainers/Yurunsoft)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imiphp-imi-migration/health.svg)

```
[![Health](https://phpackages.com/badges/imiphp-imi-migration/health.svg)](https://phpackages.com/packages/imiphp-imi-migration)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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