hhpack / migrate
Lightweight migration tool for Hack
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
Language:Shell
Requires
- hhvm: >= 3.21.0
- hhpack/color: ^1.3
- hhpack/getopt: ^1.7
- hhpack/publisher: ^1.3
- hhvm/hhvm-autoload: ^2.0
- hhvm/type-assert: ^3.3
Requires (Dev)
- facebook/fbexpect: ^2.5
- hhvm/hacktest: ^1.5
This package is auto-updated.
Last update: 2024-10-21 00:07:40 UTC
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