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

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

catchadmin/migration
====================

00PHP

Since Mar 23Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

thinkphp6 数据库迁移工具
=================

[](#thinkphp6-数据库迁移工具)

安装
--

[](#安装)

```
composer require catchadmin/migration
```

如何使用
----

[](#如何使用)

### 创建 migration

[](#创建-migration)

```
php think migrete:create Good
```

### 编写 migration

[](#编写-migration)

迁移类包含两个方法：`up` , `change` 和 `down` 。

- `up` 方法用于向数据库中添加新表、列或索引，
- `down` 方法用于撤销 `up` 方法执行的操作
- `change` 修改表结构

```
use catchAdmin\migration\Migrator;
use catchAdmin\migration\builder\Scheme;
use catchAdmin\migration\builder\Table;

class Goods extends Migrator
{
    public function up()
    {
        Scheme::create('goods_test', function (Table $table) {
            $table->id();

            $table->string('name')->default('')->comment('昵称');

            $table->smallInteger('sort')->default(0)->comment('排序');

            $table->double('price');

            $table->year('year');

            $table->timestamps();

            $table->softDelete('delete_at');
        });
    }

    public function down()
    {
        Scheme::drop('goods_test');
    }
}
```

创建完成之后，执行

```
php think migrate
```

如果需要指定执行某个 `migrate`

```
php think migrate -t migrate_name
```

查看迁移状态
------

[](#查看迁移状态)

```
php think migrate:status
```

回滚迁移
----

[](#回滚迁移)

如果要回滚最后一次迁移操作，可以使用 `Artisan` 命令 `rollback`。该命令会回滚最后「一批」的迁移，这可能包含多个迁移文件：

```
php think migrate:rollback
```

回滚某个指定的迁移文件

```
php think migrate:rollback -t migrate_name
```

通过向 `rollback `命令加上 `step` 参数，可以回滚指定数量的迁移。例如，以下命令将回滚最后五个迁移：

```
php think migrate:rollback --step=5
```

如果你想回滚全部，可以将 `step` 设置个非常大的值

数据填充
----

[](#数据填充)

### 创建填充

[](#创建填充)

```
php think make:seed Seeder
```

### 填充数据

[](#填充数据)

```
use catchAdmin\migration\Seeder;

class Good extends Seeder
{
    public function run()
    {
        // 这里填充数据
    }
}
```

### 执行填充

[](#执行填充)

```
php think seed:run
```

如果需要指定填充，可以使用下面的命令

```
php think seed:run -t Good
```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity26

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/58aeeb2b0737ee495a9d240e562b55ef5f2140d3da9c887af155b296f2086f33?d=identicon)[JaguarJack](/maintainers/JaguarJack)

---

Top Contributors

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

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/catchadmin-migration/health.svg)](https://phpackages.com/packages/catchadmin-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)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

PHPackages © 2026

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