hhpack/migrate
Composer 安装命令:
composer require hhpack/migrate
包简介
Lightweight migration tool for Hack
README 文档
README
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
-
Create a database
CREATE USER 'migrate'@'localhost' IDENTIFIED BY 'migrate'; -
Create a user
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON migrate.* TO 'migrate'@'localhost'; -
Execute unit test
You can run the test with the following command.
composer install composer test
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-05-08