2017 © Pedro Peláez
 

library migrate

SQL and PHP migration tool for your web application.

image

voilab/migrate

SQL and PHP migration tool for your web application.

  • Friday, July 17, 2015
  • by karamasoff
  • Repository
  • 0 Watchers
  • 0 Stars
  • 655 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Voilab Migrate

SQL and PHP migration tool for your web application. Put your migration files (.sql or .php) in a migration directory and voilab-migrate tool will execute them and keep your database up-to-date., (*1)

How to Install

using Composer

Create a composer.json file in your project root:, (*2)

{
    "require": {
        "voilab/migrate": "0.2.*"
    }
}

Then run the following composer command:, (*3)

$ php composer.phar update

Prerequisites

  • You need composer (at least its autoload system) to run that library.

Installation

  • create a 'migrations' directory in your project
  • copy the 'migrate.php' file from /lib/install to the root path of your project, make it executable (chmod +x) and rename it if you want
  • run the install.sql script in your database (it will create a small table that keep track of your current migration version).

Usage

For now, Voilab Migrate handle 2 types of migrations: - SQL migration - PHP migration, (*4)

SQL migration

Simply create your SQL file with the good naming convention. Name should be something like [custom name]_[version number].sql (i.e. 2014-10-21_14.sql), (*5)

PHP migration

Create a PHP file, with the same naming convention as the SQL file above. Your file should look like this:, (*6)

<?php
class Migration14 {
    public function go(\Voilab\Migrate\Migrate $migrate) {

        try {
            if ($some_custom_condition_if_you_want) {
                $sql = "UPDATE mytable SET somefield = '" . $some_custom_value . "' WHERE some_other_field='hehehe'";
                $migrate->run($sql); // the mandatory go() method receive the Migrate instance as a parameter. So you can use it here without connecting again to the database.

                // make something on the filesystem
                if (file_exists(__DIR__ . '/../app/uploads/' . $some_custom_value . '.jpg')) {
                    unlink(__DIR__ . '/../app/uploads/' . $some_custom_value . '.jpg');
                }

                echo 'My migration 14 succeeded. Yipee !'; // this text will appear in the console. This is not mandatory...
            }
        } catch (Exception $e) {
            echo "Migration 14: An error occured during the update.";
            return false;
        }
    }
}

So you simply have to define a classe named after the migration number and define a go() method in it. The go() method get the Migrate instance as its first parameter., (*7)

If you need other things from your application, just include them the way you want..., (*8)

Run migrations

When you have migrations to pass, run your (maybe renamed) 'migrate.php' script in command-line mode., (*9)

$ php migrate.php

Authors

Joel Poulin, (*10)

License

MIT Public License, (*11)

The Versions

17/07 2015

dev-master

9999999-dev https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

17/07 2015

0.2.1

0.2.1.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

17/07 2015

dev-develop

dev-develop https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

17/07 2015

0.2.0

0.2.0.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

07/01 2015

0.1.7

0.1.7.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

03/01 2015

0.1.6

0.1.6.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

21/10 2014

0.1.5

0.1.5.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

The Requires

 

20/10 2014

0.1.4

0.1.4.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

The Requires

 

23/09 2014

0.1.3

0.1.3.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

The Requires

 

21/09 2014

0.1.2

0.1.2.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

The Requires

 

21/09 2014

0.1.1

0.1.1.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

The Requires

 

21/09 2014

0.1.0

0.1.0.0 https://bitbucket.org/voilab/migrate

SQL and PHP migration tool for your web application.

  Sources   Download

MIT

The Requires