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" }
}
}
}
You can run the create command to create the database.
vendor/bin/migrate create
Use the gen command to generate a migration file.
vendor/bin/migrate gen create-users
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
To downgrade to the specified version, use the down command.
vendor/bin/migrate down 20150824010439-create-users
Restore all applied migrations.
vendor/bin/migrate reset
You can delete the database with the following command.
vendor/bin/migrate drop
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();
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');
-
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