PHPackages                             thinkphp6/thinkphp-migration-generator - 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. thinkphp6/thinkphp-migration-generator

ActiveLibrary

thinkphp6/thinkphp-migration-generator
======================================

generator migration files if you never use it

391↓100%PHP

Since Dec 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/thinkphp6/thinkphp-migration-generator)[ Packagist](https://packagist.org/packages/thinkphp6/thinkphp-migration-generator)[ RSS](/packages/thinkphp6-thinkphp-migration-generator/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Migration Generator - Mysql数据表反向迁移文件生成
======================================

[](#migration-generator---mysql数据表反向迁移文件生成)

如果你还未使用或者正想使用数据库迁移功能，但又不并不想自己写迁移文件的话，这个工具可以很好的帮助实现文件迁移， 目前提供了 Laravel5.5+ 和 Thinkphp6+ 的迁移文件的生成。

源项目:
因为原本的存在一些BUG , Fork一个版本修复下

更新日志:

- 修复DateTime大小写问题
- 增加SimpleArrayType 修复Set类型导致异常问题

安装
--

[](#安装)

```
composer require thinkphp6/thinkphp-migration-generator:dev-main
```

平台支持
----

[](#平台支持)

#### laravel

[](#laravel)

```
php artisan migration:generate
```

#### ThinkPHP

[](#thinkphp)

```
php think migration:generate

```

#### 注意

[](#注意)

> 包中提供的命令如果不能完全满足你的需求，那么你可以根据实际自定义需求。

### 定义新类型

[](#定义新类型)

- 继承 \\Doctrine\\DBAL\\Types\\Type

```
class newType extend \Doctrine\DBAL\Types\Type{}
```

- 主要实现两个方法

```
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
    return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
}

public function getName()
{
    return 'TypeName';
}
```

- 注入

```
$generator = new MigrateGenerator('thinkphp');
$generator->registerNewType([
    'TypeName' => TypeClass
]);
```

### 新增类型解析

[](#新增类型解析)

> 就是对应框架 migration 的格式

- 继承实现

```
classType extend JaguarJack\MigrateGenerator\Migration\Columns\AbstractType
{}
```

> 继承这个基类可以获取两个信息 - 获取当前 `column` 的所有信息 - 整个表结构的原始信息 这里可以得到 `DBAL` 不会提供的信息

- 必须实现的两个方法

> 因为现在就支持了 laravel 和 thinkphp 所有就定义了这两个方法

```
    public function laravelMigrationColumn():string

    public function thinkphpMigrationColumn():string
```

- 注入

```
$generator = new MigrateGenerator('thinkphp');
$generator->registerNewTypeParse([
    'TypeClassName' => ParseTypeClass
]);
```

> `TypeClassName` 指的就是新类型的类的名称 `ParseTypeClass` 也必须和 `TypeClass` 相同，这是约定，方便更好的解析。

### 其他

[](#其他)

除了提供的自定义的命令外，通过两个对外接口自己生成文件

```
$generator->getDatabase;
```

> 这个方法可以获取表信息以及字段信息等等

```
$generator->getMigrationContent;
```

> 这个方法可以获取解析后 migration 文件内容

###  Health Score

18

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e6fac12ad98dc1f0ee78b517662c310ef2556ca947dc55fbadcd07355d1a05e8?d=identicon)[ninetian](/maintainers/ninetian)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/thinkphp6-thinkphp-migration-generator/health.svg)

```
[![Health](https://phpackages.com/badges/thinkphp6-thinkphp-migration-generator/health.svg)](https://phpackages.com/packages/thinkphp6-thinkphp-migration-generator)
```

PHPackages © 2026

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