A library to handle migrations of data from your database. It uses and provides migrations with instances of doctrine dbal, giving greater flexibility to the developer. It uses the symfony console, which enables friendly and iterative help.
- Create a file in your personal project with whatever name you prefer:
Ex: example.php
<?php
declare(strict_types=1);
use AliceMigration\Management\Configuration\Configuration;
use AliceMigration\Migration\Migration;
#Path where your migration classes will be created
$pathMigrations = "/path/";
#Namespace that your migration classes meet, use the path namespace that you previously defined.
$namespace = 'PathNamespace';
#Here it can be customized because the configuration class expects an instance of the PDO
$pdo = new PDO('mysql:host=your_hostname;dbname=your_db;charset=UTF-8', $user, $pass);
#Creating the migration command console
$migration = new Migration(new Configuration($pdo, $pathMigrations, $namespace));
$migration->run();
- Now your newly created file has become a central data migration command, to access the terminal type:
php example.php
This migration command offers the possibility to add commands and sql statements using Doctrine's Dbal. To generate a class of data migration you must enter the following command in the terminal:
php example.php migrate:create
After you run the command, a class is created in the path that you have defined in the settings. Now edit the created class and add the instructions you need for your data migration.
To run your migration classes, you need to run the following command on your terminal:
php example.php migrate:run
For more information on the optional parameters of this command, run the command with the --help end on your terminal. Ex:
php example.php migrate:run --help
To roll back a migration or roll the rollback that you set, run the following command on your terminal:
php example.php migrate:revert <filename>
- filename is the class name of your data migration.
Ex:
php example.php migrate:revert MigrateVersion1546978382.php
For more information on the optional parameters of this command, run the command with the --help end on your terminal. Ex:
php example.php migrate:revert --help
Author:
Enjoy it :)