Skip to content

Data migration mechanism for php using dbal do doctrine with pdo, schema and queryBuilder The Migrations provide additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and powerful tool.

matheusbiagini/biagini-migration

Repository files navigation

Biagini Migration

Minimum PHP Version

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.

Setting.

  1. 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();
  1. Now your newly created file has become a central data migration command, to access the terminal type:
php example.php

Creating a Data Migration.

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.

Running the migrations that were created.

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

Reverting a migration.

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 :)

About

Data migration mechanism for php using dbal do doctrine with pdo, schema and queryBuilder The Migrations provide additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and powerful tool.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages