Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module Migrations #126

Open
lbcd opened this issue Aug 9, 2017 · 1 comment
Open

Module Migrations #126

lbcd opened this issue Aug 9, 2017 · 1 comment

Comments

@lbcd
Copy link

lbcd commented Aug 9, 2017

Hello,

Is it possible to have an exemple of up () migration method when using Module Migrations ?

<?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'
        ),
        'blog' => array(
            'adapter' => new Adapter\File\Flat('modules/migrationLogs/blog_migrations.log'),
            'migrations_path' => 'migrations/blog'
        )
    );
};
class AddRatingToLolCats extends Migration
{
    /**
     * Do the migration
     */
    public function up()
    {
        $sql = "ALTER TABLE `lol_cats` ADD COLUMN `rating` INT(10) UNSIGNED NULL";
      ????????????????? 
    }
@lbcd
Copy link
Author

lbcd commented Aug 9, 2017

I find a solution studying source code. I had connection in my 'phpmig.sets'

foreach($dbParams as $dbParam => $friendlyName) {
    $parametersSet[$friendlyName] = array(
        'adapter' =>
            new Adapter\PDO\Sql(
                new PDO(
                   'mysql:host=' . $ini_array[$dbParam . '.params.host'] . ';dbname=' . $ini_array[$dbParam . '.params.dbname'], $ini_array[$dbParam . '.params.username'], $ini_array[$dbParam . '.params.password'])
                , 'migrations'
            ),

        new Adapter\File\Flat(__DIR__ . DIRECTORY_SEPARATOR . 'migrations/log/' . $friendlyName . '_migrations.log'),
        'migrations_path' => 'migrations/' . $friendlyName,
        'connection' => new PDO('mysql:host=' . $ini_array[$dbParam . '.params.host'] . ';dbname=' . $ini_array[$dbParam . '.params.dbname'], $ini_array[$dbParam . '.params.username'], $ini_array[$dbParam . '.params.password'])
    );
}

Then, I can use it in up method like this

        $sql = "CREATE TABLE `test` (id INT,data VARCHAR(100));";
        if (!$this->getContainer()['phpmig.connection']->query($sql)) {
            die('error');
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant