2

I am using Phinx to migrate. https://github.com/cakephp/phinx

Now i want to use the name of my database in some special query in Migration file, the database name is specified depending on the enviroment in the phinx-config file.

    return [
    'paths' => [
        'migrations' => './database/migrations',
        'seeds' => './database/seeds',
    ],
    'environments' => [
        'default_migration_table' => 'phinxlog',
        'default_database' => 'development',
        'development' => [
            'adapter' => 'mysql',
            'host' => ,
            'name' => ,
            'user' => ,
            'pass' => ,
            'port' => 3306,
            'charset' => 'utf8',
        ],
    ],
];

I have found in the scope of the project some line

$output->writeln('<info>using database</info> ' . $envOptions['name']);

based in the vendor\robmorgan\phinx\src\Phinx\Console\Command\Migrate.php

If i start the command there is an message witch calls the cli the correct database. How i can use this $envOptions in my migrations file?

I am missing something like getConfig().

lin
  • 17,956
  • 4
  • 59
  • 83
larabee
  • 156
  • 5

1 Answers1

4

You can access environment config params like $this->getAdapter()->getOption('<paramKey>'); inside your migration:

<?php

use Phinx\Migration\AbstractMigration;

/**
 * Class InnoDB
 */
class SomeMigration extends AbstractMigration
{
    /**
     * Up
     */
    public function change()
    {
        //returns the field "name" from environment config
        $dbName = $this->getAdapter()->getOption('name'); 
    }
}
lin
  • 17,956
  • 4
  • 59
  • 83