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

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

magein/migration
================

基于phinx重新封装的面向对象形式的数据库迁移类

v4.0.1(7mo ago)02[1 PRs](https://github.com/magein/php-migration/pulls)1MITPHPPHP ^8.0

Since Aug 11Pushed 7mo agoCompare

[ Source](https://github.com/magein/php-migration)[ Packagist](https://packagist.org/packages/magein/migration)[ Docs](https://gitee.com/magein/php-migration)[ RSS](/packages/magein-migration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (9)Used By (1)

Phinx
=====

[](#phinx)

### 简介

[](#简介)

基于phinx:0.14.0数据库迁移工具

composer.json不依赖phinx:0.14.0,而是将phinx跟其依赖的包提取到phinx目录下,只保留了基础的功能

[gitee](https://gitee.com/magein/php-migration) | [composer](https://packagist.org/packages/magein/migration)

空间类型字段mysql版本最好是&gt;=5.7

### 修改

[](#修改)

1. 可以链式调用
2. 优化了命令行的参数位置(一些命令不在局限于位置)
3. 可以省略migrate参数,支持小写,下划线的方式创建

### 安装

[](#安装)

```
composer require magein/migration

```

#### 配置文件

[](#配置文件)

只保留了.php的解析, .yml格式删除

> 根目录生成phinx.php

```
return \magein\migration\PhinxConfig::config(
    [
        'environments' => [
            'default_migration_table' => 'phinx_log',
            'default_environment' => 'development',
            'production' => [
                'adapter' => 'mysql',
                'host' => 'localhost',
                'name' => 'production_db',
                'user' => 'root',
                'pass' => '',
                'port' => 3306,
                'charset' => 'utf8mb4',
                'collation' => 'utf8mb4_unicode_ci',
            ],
            'development' => [
                'adapter' => 'mysql',
                'host' => '127.0.0.1',
                'name' => 'hyt',
                'user' => 'root',
                'pass' => '',
                'port' => 3306,
                'charset' => 'utf8',
            ],
            'testing' => [
                'adapter' => 'sqlite',
                'name' => './tests/_data/database',
                'memory' => false
            ]
        ],
    ]
);
```

#### phinx

[](#phinx-1)

这里是phinx默认的命令(可参考官网的命令)

```
php phinx create CreateUserTable
php phinx migrate
php phinx -e migrate
php phinx rollback
php phinx seed:create
php phinx seed:run
```

#### 调用

[](#调用)

> 在根目录生成migrate

```
include('vendor/autoload.php');

$input = new \magein\migration\PhinxInput();
$app = new \Phinx\Console\PhinxApplication();
$app->run($input);
```

```
// 创建表
php migrate user
// 新增字段 --column 可选
php migrate user_append_xx --column xx,xx,xxx
// 移除字段 --column 可选
php migrate user_remove --column xx,xx,xxx
// user表重新命名
php migrate user_rename
// 更新字段
php migrate user_update
```

表字段

```
protected $name = 'user';

public function change()
{
    $builder = $this->builder('表描述');
    $builder->id();
    $builder->string('username', '登录账号', 30)->length(64)->unique();
    $builder->char('password', '登录账号', 32);
    $builder->integerTiny('from', '来源 1 注册 2 小程序')->default(1);
    $builder->integerSmall('age', '年龄')->nullable();
    $builder->integer('integral', '积分')->default();
    $builder->date('birthday', '生日')->nullable();
    $builder->dateTime('last_login_time', '最后一次登录时间')->nullable();
    $builder->time('notify')->comment('通知时间')->nullable();

    // 更新字段
    $builder->change();

    $builder->innoDB();
    $this->create($builder, false);
}
```

#### 执行

[](#执行)

> run migrate create

```
php migrate run
php migrate migrate
php migrate user run
php migrate run  user
php migrate rollback user
php migrate user rollback
```

当命令行包含run/migrate/rollback的时候将执行命令,不在区分顺序

### 内置字段

[](#内置字段)

#### 常规字段

[](#常规字段)

```
$builder = $this->builder('');
$builder->id();

// 用户
$builder->user->username();
$builder->user->password();
$builder->user->name();
$builder->user->nickname();
$builder->user->money();
$builder->user->balance();
$builder->user->phone();
$builder->user->email();
$builder->user->gender();
$builder->user->age();
$builder->user->birthday();
// 民族
$builder->user->ethnic();
// 籍贯
$builder->user->nativePlace();
// 用户可积累、兑换的积分系统
$builder->user->points();
// 分数或得分
$builder->user->score();
// 证件类型  身份证 港澳通行证  台胞证等
$builder->user->idType();
// 证件号码
$builder->user->idNumber();

// 常规
$builder->gen->type();
$builder->gen->title();
$builder->gen->conent();
$builder->gen->remark();
$builder->gen->sort();
$builder->gen->beginTime();
$builder->gen->startTime();
$builder->gen->endTime();
$builder->gen->status();

// 地址
$builder->addr->address();
$builder->addr->province();
$builder->addr->city();
$builder->addr->area();
$builder->addr->district();
$builder->addr->street();
$builder->addr->postcode();
$builder->addr->location();
$builder->addr->lng();
$builder->addr->lat();
```

#### 组合字段

[](#组合字段)

```
// 分类
$builder->comb->category();
// 文章
$builder->comb->article();
// 轮播图
$builder->comb->carousel();
// 银行
$builder->comb->bank();
// 订单
$builder->comb->order();
// 支付订单
$builder->comb->payOrder();
// 发表
$builder->comb->voice();
// 用户字段合集
$builder->comb->user();
// 企业
$builder->comb->business();
// 行业
$builder->comb->industry();
// 优惠劵规则
$builder->comb->couponRule();
// 附件,文件等字段合集
$builder->comb->file();
// 同时添加状态和排序
$builder->comb->statusSort();
// 同时添加开始和结束时间
$builder->comb->datetime();
// 行政区划
$builder->comb->region();
// 省市区
$builder->comb->zone();
// 省市区地址
$builder->comb->zoneAddress();
// 追加一个备注
$builder->gen->regionAddress()->remark();
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance62

Regular maintenance activity

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

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

Total

8

Last Release

235d ago

Major Versions

v1.0.0 → v4.0.02025-08-18

v2.0.1 → v4.x-dev2025-09-26

PHP version history (2 changes)v1.x-devPHP ^7.1

v4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/481454b3677ae8ec1ab0b6f58bbabdd89113c12ad1d09b22b6a19063e4cf3dd1?d=identicon)[Magein](/maintainers/Magein)

---

Top Contributors

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

### Embed Badge

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

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