Simple migrations system for php

Related tags

Migrations phpmig
Overview

Phpmig

Build Status

What is it?

Phpmig is a (database) migration tool for php, that should be adaptable for use with most PHP 5.3+ projects. It's kind of like doctrine migrations, without the doctrine. Although you can use doctrine if you want. And ironically, I use doctrine in my examples.

How does it work?

$ phpmig migrate

Phpmig aims to be vendor/framework independent, and in doing so, requires you to do a little bit of work up front to use it.

Phpmig requires a bootstrap file, that must return an object that implements the ArrayAccess interface with several predefined keys. We recommend returning an instance of Pimple, a simple dependency injection container. This is also an ideal opportunity to expose your own services to the migrations themselves, which have access to the container, such as a schema management abstraction.

Getting Started

The best way to install phpmig is using composer:

$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require davedevelopment/phpmig

You can then use the localised version of phpmig for that project

$ bin/phpmig --version

Phpmig can do a little configuring for you to get started, go to the root of your project and:

$ phpmig init
+d ./migrations Place your migration files in here
+f ./phpmig.php Create services in here
$ 

Note that you can move phpmig.php to config/phpmig.php, the commands will look first in the config directory than in the root.

Phpmig can generate migrations using the generate command. Migration files are named versionnumber_name.php, where version number is made up of 0-9 and name is CamelCase or snake_case. Each migration file should contain a class with the same name as the file in CamelCase.

$ phpmig generate AddRatingToLolCats
+f ./migrations/20111018171411_AddRatingToLolCats.php
$ phpmig status

 Status   Migration ID    Migration Name 
-----------------------------------------
   down  20111018171929  AddRatingToLolCats

Use the migrate command to run migrations

$ phpmig migrate
 == 20111018171411 AddRatingToLolCats migrating
 == 20111018171411 AddRatingToLolCats migrated 0.0005s
$ phpmig status

 Status   Migration ID    Migration Name 
-----------------------------------------
     up  20111018171929  AddRatingToLolCats
$ 

Better Persistence

The init command creates a bootstrap file that specifies a flat file to use to track which migrations have been run, which isn't great. You can use the provided adapters to store this information in your database.

<?php

# phpmig.php

use Phpmig\Adapter;
use Pimple\Container;

$container = new Container();

$container['db'] = function () {
    $dbh = new PDO('mysql:dbname=testdb;host=127.0.0.1','username','passwd');
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
};

$container['phpmig.adapter'] = function ($c) {
    return new Adapter\PDO\Sql($c['db'], 'migrations');
};

$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';

return $container;

Postgres PDO SqlPgsql

Adds support for qualifying the migrations table with a schema.

<?php

# phpmig

use Phpmig\Adapter;
use Pimple\Container;

$container = new Container();

$container['db'] = function () {
    $dbh = new PDO(sprintf('pgsql:dbname=%s;host=%s;password=%s', 'dbname', 'localhost', 'password'), 'dbuser', '');
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
};

$container['phpmig.adapter'] = function ($c) {
    return new Adapter\PDO\SqlPgsql($c['db'], 'migrations', 'migrationschema');
};

return $container;

Or you can use Doctrine's DBAL:

<?php

# phpmig.php

// do some autoloading of Doctrine here

use Phpmig\Adapter;
use Pimple\Container;
use Doctrine\DBAL\DriverManager;

$container = new Container();

$container['db'] = function () {
    return DriverManager::getConnection(array(
        'driver' => 'pdo_sqlite',
        'path'   => __DIR__ . DIRECTORY_SEPARATOR . 'db.sqlite',
    ));
};

$container['phpmig.adapter'] = function ($c) {
    return new Adapter\Doctrine\DBAL($c['db'], 'migrations');
};

$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';

return $container;

Setting up migrations with Zend Framework requires a couple additional steps. You first need to prepare the configuration. It might be in any format supported by Zend_Config. Here is an example in YAML for MySQL:

phpmig:
  tableName: migrations
  createStatement: CREATE TABLE migrations ( version VARCHAR(255) NOT NULL );

In configuration file you need to provide the table name where the migrations will be stored and a create statement. You can use one of the configurations provided in the config folder for some common RDBMS.

Here is how the bootstrap file should look:

<?php

# phpmig.php

// Set some constants
define('PHPMIG_PATH', realpath(dirname(__FILE__)));
define('VENDOR_PATH', PHPMIG_PATH . '/vendor');
set_include_path(get_include_path() . PATH_SEPARATOR . VENDOR_PATH);

// Register autoloading
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Zend_');

use Phpmig\Adapter\Zend\Db;
use Pimple\Container;

$container = new Container();

$container['db'] = function () {
    return Zend_Db::factory('pdo_mysql', array(
        'dbname' => 'DBNAME',
        'username' => 'USERNAME',
        'password' => 'PASSWORD',
        'host' => 'localhost'
    ));
};

$container['phpmig.adapter'] = function($c) {
    $configuration = null;
    $configurationFile = PHPMIG_PATH . '/config/mysql.yaml';

    if (file_exists($configurationFile)) {
        $configuration = new Zend_Config_Yaml($configurationFile, null, array('ignore_constants' => true));
    }

    return new Db($c['db'], $configuration);
};

$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';

return $container;

Example with Eloquent ORM 5.1

<?php

use Phpmig\Adapter;
use Pimple\Container;
use Illuminate\Database\Capsule\Manager as Capsule;

$container = new Container();

$container['config'] = [
    'driver'    => 'xxx',
    'host'      => 'xxx',
    'database'  => 'xxx',
    'username'  => 'xxx',
    'password'  => 'x',
    'charset'   => 'xxx',
    'collation' => 'xxx',
    'prefix'    => '',
];

$container['db'] = function ($c) {
    $capsule = new Capsule();
    $capsule->addConnection($c['config']);
    $capsule->setAsGlobal();
    $capsule->bootEloquent();

   return $capsule;
};

$container['phpmig.adapter'] = function($c) {
    return new Adapter\Illuminate\Database($c['db'], 'migrations');
};
$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';

return $container;

Writing Migrations

The migrations should extend the Phpmig\Migration\Migration class, and have access to the container. For example, assuming you've rewritten your bootstrap file like above:

<?php

use Phpmig\Migration\Migration;

class AddRatingToLolCats extends Migration
{
    /**
     * Do the migration
     */
    public function up()
    {
        $sql = "ALTER TABLE `lol_cats` ADD COLUMN `rating` INT(10) UNSIGNED NULL";
        $container = $this->getContainer(); 
        $container['db']->query($sql);
    }

    /**
     * Undo the migration
     */
    public function down()
    {
        $sql = "ALTER TABLE `lol_cats` DROP COLUMN `rating`";
        $container = $this->getContainer(); 
        $container['db']->query($sql);
    }
}

Customising the migration template

You can change the default migration template by providing the path to a file in the phpmig.migrations_template_path config value. If the template has a .php extension it is included and parsed as PHP, and the $className variable is replaced:

<?= "<?php ";?>

use Phpmig\Migration\Migration;

class <?= $className ?> extends Migration
{
    $someValue = <?= $this->container['value'] ?>; 

    /**
     * Do the migration
     */
    public function up()
    {
        $container = $this->getContainer();
    }

    /**
     * Undo the migration
     */
    public function down()
    {
        $container = $this->getContainer();
    }
}

If it uses any other extension (e.g., .stub or .tmpl) it's parsed using the sprintf function, so the class name should be set to %s to ensure it gets replaced:

<?php

use Phpmig\Migration\Migration;

class %s extends Migration
{
    /**
     * Do the migration
     */
    public function up()
    {
        $container = $this->getContainer(); 
    }

    /**
     * Undo the migration
     */
    public function down()
    {
        $container = $this->getContainer(); 
    }
}

Module Migrations

If you have an application that consists of different modules and you want to be able to separate the migration, Phpmig has a built-in way to achieve this.

<?php

/** @var Pimple\Container $container */
$container['phpmig.sets'] = function ($container) {
    return array(
        'cms' => array(
            'adapter' => new Adapter\File\Flat('modules/migrationLogs/cms_migrations.log'),
            'migrations_path' => 'migrations/cms',
            'migrations_template_path' => 'PhpmigCmsTemplate.php'
        ),
        'blog' => array(
            'adapter' => new Adapter\File\Flat('modules/migrationLogs/blog_migrations.log'),
            'migrations_path' => 'migrations/blog',
            'migrations_template_path' => 'PhpmigBlogTemplate.php',
        )
    );
};

this way each set has their own migration log and the ability to migrate changes independently of each other.

to run the set migration you just use the command below:

$ phpmig up -s <SET NAME HERE> --<VERSION HERE>

For example, if a change was made to the cms migration, you'll type in this command:

$ phpmig up -s cms --2

and the migration tool will run the migration setup for cms.

to downgrade a migration would be:

$ phpmig down -s <SET NAME HERE> --<VERSION HERE>

Multi path migrations

By default you have to provide the path to migrations directory, but you can organize your migrations script however you like and have several migrations directory. To do this you can provide an array of migration file paths to the container :

<?php

/** @var Pimple\Container $container */
$container['phpmig.migrations'] = function () {
    return array_merge(
        glob('migrations_1/*.php'),
        glob('migrations_2/*.php')
    );
};

You can then provide a target directory to the generate command. The target directory is mandatory if you haven't provided a phpmig.migrations_path config value.

$ phpmig generate AddRatingToLolCats ./migrations

Rolling Back

You can roll back the last run migration by using the rollback command

$ phpmig rollback

To rollback all migration up to a specific migration you can specify the rollback target

$ phpmig rollback -t 20111101000144

or

$ phpmig rollback --target=20111101000144

By specifying 0 as the rollback target phpmig will revert all migrations

$ phpmig rollback -t 0

You can also rollback only a specific migration using the down command

$ phpmig down 20111101000144

Using Outside CLI

In order to use the migration tool outside the cli context use Phpmig\Api\PhpmigApplication.

<?php

use Phpmig\Api\PhpmigApplication;

// require the composer autoloader
require __DIR__ . '/vendor/autoload.php';

$output = new \Symfony\Component\Console\Output\NullOutput();

// create container from bootstrap file
$container = require __DIR__ . '/tests/dom/phpmig.php';

$app = new PhpmigApplication($container, $output);

// run the migrations
$app->up();

Todo

  • Some sort of migration manager, that will take some of the logic out of the commands for calculating which migrations have been run, which need running etc
  • Adapters for Zend_Db and/or Zend_Db_Table and others?
  • Redo and rollback commands
  • Tests!
  • Configuration?
  • Someway of protecting against class definition clashes with regard to the symfony dependencies and the user supplied bootstrap?

Contributing

Feel free to fork and send me pull requests, I try and keep the tool really basic, if you want to start adding tons of features to phpmig, I'd recommend taking a look at robmorgan/phinx.

Inspiration

I basically started copying ActiveRecord::Migrations in terms of the migration features, the bootstrapping was my own idea, the layout of the code was inspired by Symfony and Behat

Copyright

Pimple is copyright Fabien Potencier. Everything I haven't copied from anyone else is Copyright (c) 2011 Dave Marshall. See LICENCE for further details

Comments
  • Support multiple connections with Illuminate database adapter

    Support multiple connections with Illuminate database adapter

    If multiple connections are defined in the Capsule Manager, this update allows the Illuminate Database Adapter to record database changes to a connection other than the default one.

    opened by jamescarlos 9
  • Patch all occurences of phpmig.sets with deep level key access w/o parent

    Patch all occurences of phpmig.sets with deep level key access w/o parent

    Hi,

    Simple bug fixes for undefined phpmig.sets keys when accessing deeply nested keys on the pimple container.

    Seems to get things working again. Tested against Pimple v3.2.3

    opened by DaveHewy 8
  • fixed PHP Warning in Illuminate/Database adapter

    fixed PHP Warning in Illuminate/Database adapter

    in fetchAll method array_map is called with the result of this statement:

    $all = $this->adapter
      ->table($this->tableName)
      ->orderBy('version')
      ->get();
    

    But get() returns an instance of \Illuminate\Support\Collection which is not accepted by array_map. There a call to toArray() has to be added to convert the Collection to an array

    opened by michael-mader 8
  • Allow out of order migrations

    Allow out of order migrations

    One huge improvement to migration handling when you're dealing with pull requests which may be merged out of order is the ability to run migrations out of order.

    What does that mean exactly? It means finding and sorting all migrations which exist but have not been processed, then processing those migrations (in order).

    For example. Assume we have the following migrations in our database

    | version | | --- | | 20160314000000 | | 20160315000000 | | 20160316000000 |

    Now suppose we merge a new migration in. It's called 20160315060000_SomeTask.php. We can't run it. Instead we have to rollback to 20160315000000, then migrate forward again. This is a huge pain.

    With a setting (disabled by default) allowing any migration to be processed that hasn't been processed we'd have:

    | version | | --- | | 20160314000000 | | 20160315000000 | | 20160316000000 | | 20160315060000 |

    opened by clphillips 6
  • Simplified custom migration templates

    Simplified custom migration templates

    I was adding a custom migration template to a project the other day and I noticed that because the template gets included, obviously it also gets parsed, so I ended up with this monstrosity of a template to get things working:

    <?php
    echo <<<PHP
    <?php
    use Phpmig\Migration\Migration;
    
    class $className extends Migration
    {
            /**
             * Do the migration.
             */
            public function up()
            {
                \$container = \$this->getContainer();
            }
    
            /**
             * Undo the migration.
             */
            public function down()
            {
                \$container = \$this->getContainer();
            }
    }
    
    PHP;
    ?>
    

    I've submitted a pull request that changes the way the custom template is imported to use file_get_contents() and sprintf so that templates become much simpler to write:

    <?php
    use Phpmig\Migration\Migration;
    
    class %s extends Migration
    {
            /**
            * Do the migration.
            */
            public function up()
            {
                $container = $this->getContainer();
            }
    
            /**
             * Undo the migration.
            */
            public function down()
            {
                $container = $this->getContainer();
            }
    }
    
    

    I've also added a bit of documentation to explain how to use a custom migration template.

    I'd appreciate any comments on this change. Thanks.

    opened by ziadoz 6
  • Unable to catch exceptions

    Unable to catch exceptions

    I have a particularly long running migration that fails out because of the usual "MySQL server has gone away"

    I'm trying to catch the PDOExceptions for that if it does, just reconnect, however even just a basic try/catch around my code doesn't seem to be triggering my catches.

    Even something as basic as

    
    public function up(){
    
        try {
            causeException();
        } catch (\Exception $e) {
            var_dump($e);
            die();
        }
    }
    

    I'm getting img before any handling of the exception inside my catch block.

    Is there anything from phpmig that is intercepting exceptions?

    opened by Zxurian 5
  • generate an initial migration from an existing db

    generate an initial migration from an existing db

    I already have a db created and I would like to use phpmig now, but I need to generate the migrations with my current table structures. Is this possible?

    opened by andrezap 5
  • All migrations down

    All migrations down

    Hi. I have implemented phpmig in my project long time ago.

    Everything goes fine, but today, i've tried to migrate a new database migration to my server, in local it works pretty well, but in my RC server i've found ALL the migrations seems to be down in 'phpmig check':

    $ bin/phpmig check
    PHP Warning:  array_map(): Argument #2 should be an array in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Adapter/Illuminate/Database.php on line 62
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    PHP Warning:  in_array() expects parameter 2 to be array, null given in /var/www/api/vendor/davedevelopment/phpmig/src/Phpmig/Console/Command/CheckCommand.php on line 44
    
     Status   Migration ID    Migration Name
    -----------------------------------------
       down  20150101160236  CreateDBSeedsTable
       down  20151209133248  CreateRoleTable
       down  20151209160524  CreateUserTable
       down  20151209160530  CreateCompanyTable
       down  20151209160534  CreateTeamTable
       down  20151209175730  CreateTeamUserTable
       down  20151218102533  CreateTeamBeatTable
       down  20151218103048  CreateTeamBeatLabelTable
       down  20151222134913  CreateUserTeamBeatTable
       down  20151222152231  CreateTeamBeatValue
       down  20151222161002  CreateAnnotationTypeTable
       down  20151222161128  CreateAnnotationTable
       down  20151222171550  CreateUserInvitationTable
       down  20160111134935  CreateCommercialFormTable
       down  20160121160131  CreatePriceTable
       down  20160121160155  CreateCouponTable
       down  20160123120518  CreatePaymentTable
       down  20160218153809  AlterPriceTable
       down  20160218153831  AlterPaymentTable
       down  20160304100600  AlterUserTable
       down  20160308172803  AlterTeamTable
       down  20160309123010  CreateTeamBeatQuestionTable
       down  20160324225151  TeamGroup
       down  20160427203510  Goal
       down  20160501174940  StripeOnTeam
       down  20160502232915  NameOnPrice
       down  20160514142910  DynamicTips
       down  20160629123417  Statistics
       down  20160718173455  OnboardingStatus
       down  20160809100753  RoleId
       down  20160826115237  AnnotationDate
       down  20160915122009  CompanySector
    

    But in fact, migrations are on my database except the last one (the new one). What's happening here? Can you help me to understand?

    Thanks!!

    opened by rayoplateado 5
  • status command show 2147483647 at missing.

    status command show 2147483647 at missing.

    $ bin/phpmig --version
    phpmig version dev
    
    $ bin/phpmig status
    
     Status   Migration ID    Migration Name
    -----------------------------------------
       up  20150427162348  CreatePickupProduct
       up      2147483647  ** MISSING **
    
    opened by kuwa72 5
  • Only init the migrations if they will be executed.

    Only init the migrations if they will be executed.

    • No need to init if migration is not used.
    • Container is now available when init is executed.
    • Cannot start dialog within "status" command. (Because init is not executed at construction time.)

    Fixes #38

    opened by reenl 5
  • Taken care of the composer dependencies and the test & build procedures

    Taken care of the composer dependencies and the test & build procedures

    Please refer to the individual commits for details.

    Basically the Phing buid is now more flexible. The writing and running of tests is set. The composer dependencies are fixed (Pimple moved away from the src)

    opened by petsagouris 5
  • Update for Symfony 6.x and drop support for older versions

    Update for Symfony 6.x and drop support for older versions

    It's time to drop support for older versions. If you need an older PHP version you should use an older version of the package. I've added support for Symfony 6.x

    opened by ruben-haegeman 0
  • Migration::__construct()

    Migration::__construct() "final" key word decreases usability

    The constructor's signature is final public function __construct()

    I would like to make a base class for my migrations that extends Phpmig\Migration\Migration and does some custom configuration/initilization tasks.

    The logical goto for that is the constructor, however, I cannot do that, because the parent class's constructor is marked final.

    Please remove this in a future version

    opened by daimaxiong 1
  • added DBAL3 class for using with doctrine/dbal 3 version

    added DBAL3 class for using with doctrine/dbal 3 version

    adapter for doctrine dbal version 3.0 and above. this adapter is copy of Phpmig\Adapter\Doctrine\DBAL with fixed Connection methods calls. more info about changes in version 3 here: https://www.doctrine-project.org/2020/11/17/dbal-3.0.0.html

    opened by dmnbars 1
  • Suggests/Request/Proposal : Separate Adapter.

    Suggests/Request/Proposal : Separate Adapter.

    Why not separating adapter as sub-package of phpmig/phpmig

    For example, for codeigniter user, their not need Zend, Illuminate, Doctrine adapter, their can install specific adapter for codeigniter(only) like phpmig/phpmig-adapter-codeigniter, and package phpmig/phpmig-adapater-codeigniter will depends phpmig/phpmig as core.

    then codeigniter user can install with:

    {
    
    .....
      "require": {
        "phpmig/phpmig-adapter-codeigniter": "*",
         .....
      }
    
    ....
    }
    

    project tree of phpmig/phpmig : (core)

    +-- src/
    |     +- Adapter/
    |     |      +- File/Flat.php
    |     |      +- Pdo/ (all \Phpmig\Adapater\Pdo\  class files)
    |     |      +- AdapterInterface.php
    |     +- Command/(all class of \Phpmig\Command ).php
    |     +- Migration /(all class of \Phpmig\Migration ).php
    |     +- [other files]
    +-- [other files]
    +-- composer.json
    

    And project tree of phpmig/phpmig-adapter-codeigniter :

    +-- src/
    |     +-- Adapter/
    |           +-- Codeigniter/
    |                  +-- Db.php
    +-- composer.json
    

    and phpmig/phpmig-adapter-codeigniter/composer.json be like:

    {
    ......
    "require": {
        "phpmig/phpmig": "<version>",
     }
    ......
    }
    

    with this methode, codeigniter user will haven't class Phpmig\Adapter\ {Zend, Illuminate, Doctrine} cause their installing spasific adapter for codeigniter (only).

    also for zendframework user, their can installing specific adapter package like phpmig/phpmig-adapter-zend and project tree of phpmig/phpmig-adapter-zend be like:

    +-- src/
    |    +-- Adapter/
    |           +-- Zend/
    |                 +-- (all adapter class for zf ) .php
    +-- composer.json
    

    you can use it for each adapter. Thanks.

    opened by amsitlab 1
  • Allow to change migration basename format

    Allow to change migration basename format

    By default, the migration file basename is:

    $basename = date('YmdHis') . '_' . $migrationName . '.php';
    

    Could it be possible to allow to change this by providing a callback? For example, something like:

    $callback = $this->container['phpmig.basename_callback'] ?? null;
    $basename = $callback ? $callback($migrationName) : date('YmdHis') . '_' . $migrationName . '.php'
    

    This sould not introduce BC break.

    opened by Arcesilas 0
Releases(v1.6.1)
Owner
Dave Marshall
Dave Marshall is a software engineer, who has been building web applications with various technologies since around 2004.
Dave Marshall
PHP Database Migrations for Everyone

Phinx: Simple PHP Database Migrations Intro Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minute

CakePHP 4.3k Jan 7, 2023
Framework agnostic database migrations for PHP.

Phoenix Framework agnostic database migrations for PHP. Features Validation all settings in migration before executing first query Multiple migration

Michal Lulco 148 Nov 19, 2022
php 5.3 Migration Manager

#What are Database Migrations? Migrations are a convenient way for you to alter your database in a structured and organized manner. You could edit fra

Lewis Dyer 38 Sep 28, 2022
Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.

Laravel Migrations Generator Generate Laravel Migrations from an existing database, including indexes and foreign keys! Upgrading to Laravel 5.4 Pleas

Bernhard Breytenbach 3.3k Dec 30, 2022
Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.

Laravel Migrations Generator Generate Laravel Migrations from an existing database, including indexes and foreign keys! This package is cloned from ht

Kit Loong 1.4k Jan 1, 2023
Simple migrations system for php

Phpmig What is it? Phpmig is a (database) migration tool for php, that should be adaptable for use with most PHP 5.3+ projects. It's kind of like doct

Dave Marshall 561 Jan 1, 2023
Tables migrations seeded with data according to the Algerian education system structure.

Laravel algerian education system structure If you are building a Learning Management System or a School Management System and targeting the Algerian

Elaborate Code 12 Oct 8, 2022
A Simple MVC PHP Framework, integrated with lot of features such as Session, Cookies, Migrations, Database, Factories, Seeding, Bootstrap and Tailwind CSS

Navite A Simple MVC PHP Framework, integrated with lot of features such as Session, Cookies, Migrations, Database, Factories, Seeding, Bootstrap and T

Celionatti 2 Aug 22, 2022
PHP Database Migrations for Everyone

Phinx: Simple PHP Database Migrations Intro Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minute

CakePHP 4.3k Jan 7, 2023
Framework agnostic database migrations for PHP.

Phoenix Framework agnostic database migrations for PHP. Features Validation all settings in migration before executing first query Multiple migration

Michal Lulco 148 Nov 19, 2022
PHP Database Migrations for Everyone

Phinx: Simple PHP Database Migrations Intro Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minute

CakePHP 4.3k Jan 7, 2023
Validate PHP database migration files for compliance with best practices. Ensure db migrations are irreversible.

PHP DB Migration Validator Introduction In modern PHP frameworks such as Symfony and Laravel, migrations usually have up and down methods. In up metho

Anton Komarev 17 Dec 14, 2022
A MySQL Workbench plugin which exports a Model to Laravel 5 Migrations

MySQL Workbench Export Laravel 5 Migrations Plugin A MySQL Workbench plugin that allows for exporting a model to Laravel 5 migrations that follow PSR-

Brandon Eckenrode 902 Jan 2, 2023
Migrations module for ProcessWire

ProcessDbMigrate Introduction This module is designed to ease the problem of migrating database changes from one PW environment to another.

Mark Evens 9 Nov 3, 2022
Automatic Laravel model migrations.

Laravel Automatic Migrations Automatic Laravel model migrations. Instead of having to create and manage migration files, this package allows you to sp

null 38 Nov 11, 2022
Generate migrations from existing database structures

Laravel Migration Generator Generate migrations from existing database structures, an alternative to the schema dump provided by Laravel. A primary us

Bennett Treptow 404 Jan 1, 2023
Elasticsearch migrations for Laravel

Elastic Migrations Elasticsearch migrations for Laravel allow you to easily modify and share indices schema across the application's environments. Con

Ivan Babenko 151 Dec 20, 2022
Extract SQL statements from migrations

This is my package MigrationToSql To install: composer require bcleverly/migrationtosql --dev This repo is here to help you extract the SQL queries fr

Ben 4 Apr 15, 2022
Helper for opencart migrations

Helper for opencart migrations

Pekhov Anton 1 Nov 6, 2022
The MX_PhinxMigrations module integrates Phinx database migrations into Magento 2

MX Phinx Migrations About The MX_PhinxMigrations module integrates Phinx database migrations into Magento 2 as a replacement for the built-in setup:up

Inviqa 34 Jul 30, 2021