定制 hhpack/migrate 二次开发

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

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

hhpack/migrate

Composer 安装命令:

composer require hhpack/migrate

包简介

Lightweight migration tool for Hack

README 文档

README

CircleCI

Basic usage

First place the database.json of the configuration file in the config directory.
Please specify the setting referring to the following.

  • type - the type of migration, it only supports SQL base.
  • path - the directory of the migration file.
  • enviroments - Database connection setting for environment.
{
  "type": "sql",
  "path": "db/migrate",
  "enviroments": {
    "development": {
      "host": "localhost",
      "port": 3306,
      "name": "migrate",
      "user": { "ENV": "DB_USERNAME" },
      "password": { "ENV": "DB_PASSWORD" }
    }
  }
}

Create a database

You can run the create command to create the database.

vendor/bin/migrate create

Generate a migration file

Use the gen command to generate a migration file.

vendor/bin/migrate gen create-users

Upgrade of schema

Use the up command to upgrade the schema.
You can upgrade to a specific version by specifying the --to option.

vendor/bin/migrate up

or

vendor/bin/migrate up --to=20150824010439-create-users

Downgrade of schema

To downgrade to the specified version, use the down command.

vendor/bin/migrate down 20150824010439-create-users

Reset of schema

Restore all applied migrations.

vendor/bin/migrate reset

Drop database

You can delete the database with the following command.

vendor/bin/migrate drop

Migrator

Current version supports SQL based migration.

use HHPack\Migrate\Migrator;
use HHPack\Migrate\SqlMigrationLoader;
use HHPack\Migrate\DatabaseClient;

$mysql = await DatabaseClient::createConnection('mysql:dbname=migrate;port=3306', 'migrate', 'migrate');
$loader = new SqlMigrationLoader(__DIR__ . '/sql/migrations');

$migrator = new Migrator($loader, $mysql);

await $migrator->upgrade();

Downgrade of schema

use HHPack\Migrate\Migrator;
use HHPack\Migrate\SqlMigrationLoader;
use HHPack\Migrate\DatabaseClient;

$mysql = await DatabaseClient::createConnection('mysql:dbname=migrate;port=3306', 'migrate', 'migrate');
$loader = new SqlMigrationLoader(__DIR__ . '/sql/migrations');

$migrator = new Migrator($loader, $mysql);

await $migrator->downgrade('20150825102100-create-posts');

Run the test

  1. Create a database

     CREATE USER 'migrate'@'localhost' IDENTIFIED BY 'migrate';
    
  2. Create a user

     GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON migrate.* TO 'migrate'@'localhost';
    
  3. Execute unit test

    You can run the test with the following command.

     composer install
     composer test
    

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固