Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hot to set PostgreSQL schema for table in Doctrine mapping?

I have two Symfony applications mapped to the same PgSQL database. Both applications use FOSUserBundle so I'm trying to handle users in different schemas. Reading and doing some research on Google I build my entities as follow:

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

Then I tried from Symofny2 shell the following:

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 >

But tables was generated on public schema and not in internal schema as I want, what I did wrong? Any way to create the tables in different schemas?

like image 322
ReynierPM Avatar asked Aug 07 '14 23:08

ReynierPM


2 Answers

As a workaround, you can use SCHEMA.TABLE as table name:

@ORM\Table(name="internal.internal_users")
like image 179
Salem Avatar answered Sep 20 '22 08:09

Salem


Since Doctrine ORM 2.5 you can use the schema attribute (Reference):

@ORM\Table(schema="internal")

Or use schema option in yaml driver:

App\Entity\InternalUser:
  table: internal_users
  schema: internal
like image 30
Iván Pérez Avatar answered Sep 21 '22 08:09

Iván Pérez