Doctrine映射和PostgreSQL模式

Rey*_*rPM 6 php postgresql database-schema symfony doctrine-orm

我有两个Symfony应用程序映射到相同的PgSQL数据库.两个应用程序都使用FOSUserBundle,所以我试图处理不同模式的用户.阅读并对Google进行一些研究我按照以下方式构建我的实体:

/**
 * @ORM\Entity
 * @ORM\Table(name="internal_users", schema="internal")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
 */
class InternalUser extends BaseUser
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

然后我从Symofny2 shell尝试了以下内容:

Symfony > doctrine:schema:validate
[Mapping]  OK - The mapping files are correct.
[Database] FAIL - The database schema is not in sync with the current mapping file.
The command terminated with an error status (2)
Symfony > doctrine:schema:update --force
Updating database schema...
Database schema updated successfully! "14" queries were executed
Symfony >
Run Code Online (Sandbox Code Playgroud)

但是表格是在public架构上生成的,而不是internal我想要的架构,我做错了什么?有什么方法可以在不同的模式中创建表吗?

Ivá*_*rez 7

从 Doctrine ORM 2.5 开始,您可以使用该schema属性(参考):

@ORM\Table(schema="internal")
Run Code Online (Sandbox Code Playgroud)

或者使用schemayaml 驱动程序中的选项:

App\Entity\InternalUser:
  table: internal_users
  schema: internal
Run Code Online (Sandbox Code Playgroud)


Sal*_*lem 5

解决方法是,可以将其SCHEMA.TABLE用作表名:

@ORM\Table(name="internal.internal_users")
Run Code Online (Sandbox Code Playgroud)