Php 我可以在Phinx迁移中使用两种不同的环境吗?
我使用phinx来管理我的数据库,我需要从一个数据库收集数据并将其插入另一个数据库 我在配置文件中定义了两个环境,如下所示:Php 我可以在Phinx迁移中使用两种不同的环境吗?,php,database-migration,phinx,Php,Database Migration,Phinx,我使用phinx来管理我的数据库,我需要从一个数据库收集数据并将其插入另一个数据库 我在配置文件中定义了两个环境,如下所示: 'environments' => [ 'default_database' => 'current', 'current' => [ 'adapter' => 'mysql', 'host' => '127.0.0.1', 'name'
'environments' => [
'default_database' => 'current',
'current' => [
'adapter' => 'mysql',
'host' => '127.0.0.1',
'name' => 'old',
'user' => 'root',
'pass' => '*****',
'port' => '3306',
'charset' => 'utf8',
],
'new' => [
'adapter' => 'mysql',
'host' => '127.0.0.1',
'name' => 'new',
'user' => 'root',
'pass' => '*****',
'port' => '3306',
'charset' => 'utf8',
]
],
我试图实现的是这样的目标:
public function up () {
// The environment is 'current' by default
$data = $this->fetchAll("SELECT * FROM old_table WHERE x");
// Change environment somehow
$this->environment('new')
$this->table('new_table')->insert($data);
}
这可能吗?我在上找不到任何东西。在phinx代码中查找,他们在执行迁移时会这样做
public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP, $fake = false)
{
$direction = ($direction === MigrationInterface::UP) ? MigrationInterface::UP : MigrationInterface::DOWN;
$migration->setMigratingUp($direction === MigrationInterface::UP);
$startTime = time();
$migration->setAdapter($this->getAdapter());
迁移中有可用的setAdapter,因此可以使用它。我更愿意将此写在注释中,因为这不是一个真正的答案,但我没有足够的字符查看phinx代码,它们在执行迁移时会这样做
public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP, $fake = false)
{
$direction = ($direction === MigrationInterface::UP) ? MigrationInterface::UP : MigrationInterface::DOWN;
$migration->setMigratingUp($direction === MigrationInterface::UP);
$startTime = time();
$migration->setAdapter($this->getAdapter());
迁移中有可用的setAdapter,因此可以使用它。我宁愿写在评论里,因为这不是一个真正的答案,但我没有足够的角色