我如何在 Phinx 中获取数据库名称?
How i can getDatabaseName in Phinx?
我正在使用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']);
基于vendor\robmorgan\phinx\src\Phinx\Console\Command\Migrate.php
如果我启动命令,会出现一条消息 调用 cli 正确的数据库。
我如何在我的迁移文件中使用这个 $envOptions?
我缺少像 getConfig() 这样的东西。
您可以在迁移中访问 环境配置参数 ,例如 $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');
}
}
我正在使用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']);
基于vendor\robmorgan\phinx\src\Phinx\Console\Command\Migrate.php
如果我启动命令,会出现一条消息 调用 cli 正确的数据库。 我如何在我的迁移文件中使用这个 $envOptions?
我缺少像 getConfig() 这样的东西。
您可以在迁移中访问 环境配置参数 ,例如 $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');
}
}