我正在使用Phinx进行迁移。https://github.com/cakephp/phinx
现在,我想在迁移文件中的某些特殊查询中使用数据库的名称,该数据库名称是根据phinx-config文件中的环境指定的。
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',
],
],
];
我在项目范围内发现了一些内容
$output->writeln('<info>using database</info> ' . $envOptions['name']);
基于供应商\ robmorgan \ phinx \ src \ Phinx \ Console \ Command \ Migrate.php
如果我启动命令,则有一条消息,女巫称cli为正确的数据库。我如何在迁移文件中使用此$ envOptions?
我缺少类似getConfig()的东西。
您可以访问环境配置PARAMS像$this->getAdapter()->getOption('<paramKey>');
迁移里面:
<?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');
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句