定制 jmsfwk/fluent-phinx 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jmsfwk/fluent-phinx

Composer 安装命令:

composer require jmsfwk/fluent-phinx

包简介

Laravel style migrations with Phinx

README 文档

README

Laravel-style migrations for Phinx.

Introduction

Phinx provides a way to declare schemas in migrations, but it's somewhat difficult to use because of the array of options that vary by column type.

Fluent Phinx provides a fluent Laravel-style schema builder to simplify writing and reading migrations.

Migration Structure

Fluent Phinx relies on regular Phinx migration files, with either a change method or up/down method pair.

The Fluent trait can be used to add fluent functionality to the migration file.

<?php

use jmsfwk\FluentPhinx\Fluent;
use jmsfwk\FluentPhinx\Schema\Blueprint;
use Phinx\Migration\AbstractMigration;

class CreateUsersTable extends AbstractMigration
{
    use Fluent;

    public function change()
    {
        $this->create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            
            $table->id = false; // Turn off automatic id column
            $table->primary_key = 'id'; // Set the 'id' column as the primary key
        });
    }
}

Tables

Creating Tables

To create a new database table, use the create method on from the Fluent trait. The create method accepts two arguments: the first is the name of the table, while the second is a closure which receives a Blueprint object that may be used to define the new table:

$this->create('users', function (Blueprint $table) {
    $table->increments('id');
});

When creating the table, you may use any of the schema builder's column methods to define the table's columns.

Updating Tables

To update a table the update method from the Fluent trait can be used. Like the create method this will accept two arguments: the name of the table, and a closure that receives a Blueprint object to define the changes.

$this->update('users', function (Blueprint $table) {
    $table->integer('votes');
});

Table Options

You may use the following properties on the schema builder to define the table's options:

Command Description
$table->engine = 'InnoDB'; Specify the table storage engine (MySQL).
$table->collation = 'utf8mb4_unicode_ci'; Specify a default collation for the table (MySQL).
$table->comment = 'Explain something'; Specify a comment for the table.
$table->id = 'id' The name of the automatically created id field (set to false to disable).
$table->primary_key = 'id' The column to use as the primary key (can be set to an array of columns).
$table->signed = false Whether the primary key is signed (defaults to true).

Indexes

Creating Indexes

Indexes can be added in two places, from the column definition and from the Blueprint object.

From the column you can pass the index name to the index method.

$table->string('email')->unique();

To create an index after defining the column, you should call the unique method on the schema builder blueprint. This method accepts the name of the column that should receive a unique index:

$table->unique('email');

You may pass an array of columns to an index method to create a compound (or composite) index:

$table->index(['account_id', 'created_at']);

When creating an index you may pass a second argument to the method to specify the index name:

$table->unique('email', 'unique_email');

Available Index Types

Command Description
$table->primary('id'); Adds a primary key.
$table->primary(['id', 'parent_id']); Adds composite keys.
$table->unique('email'); Adds a unique index.
$table->index('state'); Adds an index.

jmsfwk/fluent-phinx 适用场景与选型建议

jmsfwk/fluent-phinx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 889 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「migrations」 「laravel」 「phinx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jmsfwk/fluent-phinx 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jmsfwk/fluent-phinx 我们能提供哪些服务?
定制开发 / 二次开发

基于 jmsfwk/fluent-phinx 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 889
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2020-11-26