peehaa/migres 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

peehaa/migres

Composer 安装命令:

composer create-project peehaa/migres

包简介

Postgresql migration tool

README 文档

README

The PostgreSQL migration tool

Latest Stable Version Build Status Build status Coverage Status License

Requirements

  • PHP 7.4
  • PostgreSQL 9.5

Usage

Note: this is alpha software. Do not use in production (yet). I would appreciate if you could test it and provide feedback in GitHub issues. <3

Warning: never allow untrusted input in table specifications as all migrations are translated to raw SQL!

  • Add the project using composer composer install peehaa/migres
  • Run the setup ./vendor/bin/migres setup
  • Run without arguments to view the available commands ./vendor/bin/migres

All native PostgreSQL data types are implemented and the list can be found at: https://github.com/PeeHaa/migres/tree/master/src/DataType

TOC

Creating a table

<?php declare(strict_types=1);

namespace Vendor\Migrations;

use PeeHaa\Migres\DataType\BigSerial;
use PeeHaa\Migres\DataType\Boolean;
use PeeHaa\Migres\DataType\CharacterVarying;
use PeeHaa\Migres\MigrationSpecification;
use PeeHaa\Migres\Specification\Table;

class CreateTable extends MigrationSpecification
{
    public function change(): void
    {
        $this->createTable('users', function (Table $table) {
            $table->addColumn('id', new BigSerial());
            $table->addColumn('is_admin', new Boolean())->notNull()->default(false);
            $table->addColumn('name', new CharacterVarying(128))->notNull();
            $table->addColumn('email_address', new CharacterVarying(255))->notNull();
            $table->primaryKey('id');
            $table->addIndex('users_name', 'name');
            $table->addUniqueConstraint('email_address_unq', 'email_address');
        });
    }
}

Renaming a table

<?php declare(strict_types=1);

namespace Vendor\Migrations;

use PeeHaa\Migres\MigrationSpecification;

class RenameTable extends MigrationSpecification
{
    public function change(): void
    {
        $this->renameTable('users', 'members');
    }
}

Dropping a table

<?php declare(strict_types=1);

namespace Vendor\Migrations;

use PeeHaa\Migres\MigrationSpecification;

class RenameTable extends MigrationSpecification
{
    public function change(): void
    {
        $this->dropTable('members');
    }
}

Table methods

The table object defines the following methods:

Table::addColumn(string $name, \Migres\DataType\Type $dataType)

$table->addColumn('column_name', new Integer());
$table->addColumn('column_name', new Integer())->notNull;
$table->addColumn('column_name', new Integer())->default(12);

Table::dropColumn(string $name)

$table->dropColumn('column_name');

Table::renameColumn(string $oldName, string $newName)

$table->renameColumn('old_name', 'new_name');

Table::changeColumn(string $name, \Migres\DataType\Type $dataType)

$table->changeColumn('column_name', new IntegerType());
$table->changeColumn('column_name', new IntegerType())->notNull();
$table->changeColumn('column_name', new IntegerType())->default(12);

Table::primaryKey(string $column, [string ...$columns])

$table->primaryKey('column_name');
$table->primaryKey('column_name1', 'column_name2');

Table::dropPrimaryKey([string $name])

$table->dropPrimaryKey();
$table->dropPrimaryKey('table_name_pkey');

Table::namedPrimaryKey(string $name, string $column, [string ...$columns])

$table->namedPrimaryKey('custom_name_pkey', 'column_name');
$table->namedPrimaryKey('custom_name_pkey', 'column_name1', 'column_name2');

Table::renamePrimaryKey(string $oldName, string $newName)

$table->renamePrimaryKey('old_name', 'new_name');

Table::addUniqueConstraint(string $constraintName, string $column, [string ...$columns])

$table->addUniqueConstraint('constraint_name', 'column_name');
$table->addUniqueConstraint('constraint_name', 'column_name1', 'column_name2');

Table::dropUniqueConstraint(string $constraintName)

$table->dropUniqueConstraint('constraint_name');

Table::addIndex(string $indexName, string $column, [string ...$columns])

$table->addIndex('name_idx', 'column_name');
$table->addIndex('name_idx', 'column_name DESC');
$table->addIndex('name_idx', 'column_name1 DESC', 'column_name2 DESC');

Table::addBtreeIndex(string $indexName, string $column, [string ...$columns])

$table->addBtreeIndex('name_idx', 'column_name');
$table->addBtreeIndex('name_idx', 'column_name DESC');
$table->addBtreeIndex('name_idx', 'column_name1 DESC', 'column_name2 DESC');

Table::addHashIndex(string $indexName, string $column, [string ...$columns])

$table->addHashIndex('name_idx', 'column_name');
$table->addHashIndex('name_idx', 'column_name DESC');
$table->addHashIndex('name_idx', 'column_name1 DESC', 'column_name2 DESC');

Table::addGistIndex(string $indexName, string $column, [string ...$columns])

$table->addGistIndex('name_idx', 'column_name');
$table->addGistIndex('name_idx', 'column_name DESC');
$table->addGistIndex('name_idx', 'column_name1 DESC', 'column_name2 DESC');

Table::addGinIndex(string $indexName, string $column, [string ...$columns])

$table->addGinIndex('name_idx', 'column_name');
$table->addGinIndex('name_idx', 'column_name DESC');
$table->addGinIndex('name_idx', 'column_name1 DESC', 'column_name2 DESC');

Table::dropIndex(string $indexName)

$table->dropIndex('name_idx');

Table::addCheck(string $checkName, string $expression)

$table->addCheck('bigger_than_10_chk', 'column_name > 10');

Table::dropCheck(string $checkName)

$table->dropCheck('bigger_than_10_chk');

Command line

Setup

./vendor/bin/migres setup

This will run the setup wizard which guides you through the process of setting up the configuration.

Create new migration

./vendor/bin/migres create NewMigrationName

This will create a new migration and writes the file to the migrations directory.

Run migrations

./vendor/bin/migres migrate [-v[v][v]]

Run the migrations

Run rollbacks

./vendor/bin/migres rollback [-v[v][v]]

Rolls back the migrations

peehaa/migres 适用场景与选型建议

peehaa/migres 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 17, 最近一次更新时间为 2019 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 peehaa/migres 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-25