多个DB Schema&使用Doctrine2&amp ;;迁移PostgreSQL的

时间:2015-10-01 14:48:17

标签: postgresql symfony pdo doctrine-orm schema

我有一个包含多个模式的PG数据库。

我有一个symfony2应用程序,只需要连接其中一个。

如果我没有配置任何内容,默认情况下,Doctrine2会搜索所有模式,以便尝试在桌面上SELECT进行配置。

我按照这个回答:symfony2 + doctrine2@postgresql setting a schema

现在它似乎只出现在我指定的shema中,但它仍在寻找我的模式中没有的一些表,但在其他表中。

当我执行ldoctrine:migrations:diff

[Doctrine\DBAL\DBALException]                                                                     
  An exception occurred while executing 'SELECT min_value, increment_by FROM "pgstatspacknameid"':  
  SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "pgstatspacknameid" does not exist           
  LINE 1: SELECT min_value, increment_by FROM "pgstatspacknameid"                                   
                                              ^                                                     

  [PDOException]                                                                           
  SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "pgstatspacknameid" does not exist  
  LINE 1: SELECT min_value, increment_by FROM "pgstatspacknameid"                          
                                              ^      

因此,遵循学说迁移文档,我在连接配置中添加了这一行:

        schema_filter: ~^(?!pgstats)~

它仍然总是试图在这些表中制作SELECT ......

1 个答案:

答案 0 :(得分:0)

您需要使用--db-configuration选项来执行migrate命令。 它将配置文件作为参数。 尝试使用配置文件的以下内容。

<?php
return array(
    "driverClass"=>"AppBundle\Driver",
    "host" => "localhost",
    "user" => "test",
    "password" => "test",
    "dbname" => "test"
        );
?>

此外,我更改了vendor / doctrine / dbal / lib / Doctrine / DBAL / SchemaPostgreSqlSchemaManager.php,以便始终将模式添加到序列名称中。

像这样:

/**
 * {@inheritdoc}
 */
protected function _getPortableSequencesList($sequences)
{
    $sequenceDefinitions = array();
    foreach ($sequences as $sequence) {//+ || true
        if ($sequence['schemaname'] != 'public' || true) {
            $sequenceName = $sequence['schemaname'] . "." . $sequence['relname'];
        } else {
            $sequenceName = $sequence['relname'];
        }

        $sequenceDefinitions[$sequenceName] = $sequence;
    }
    $list = array();

    foreach ($this->filterAssetNames(array_keys($sequenceDefinitions)) as $sequenceName) {
        $list[] = $this->_getPortableSequenceDefinition($sequenceDefinitions[$sequenceName]);
    }
    return $list;
}

/**
 * {@inheritdoc}
 */
protected function getPortableNamespaceDefinition(array $namespace)
{
    return $namespace['nspname'];
}

/**
 * {@inheritdoc}
 */
protected function _getPortableSequenceDefinition($sequence)
{//+ || true
    if ($sequence['schemaname'] != 'public' || true) {
        $sequenceName = $sequence['schemaname'] . "." . $sequence['relname'];
    } else {
        $sequenceName = $sequence['relname'];
    }

    $data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));

    return new Sequence($sequenceName, $data[0]['increment_by'], $data[0]['min_value']);
}

(在假定架构名称的地方添加了或者真实的地方!=&#39; public&#39;)