简体   繁体   中英

How to update multiple schema in postgresql with Symfony 2.8.26 & doctrine orm

We have the symfony 2.8.26 project with doctrine orm.
We managed to connect to postgresql with multiple schema's in single database.
Now when we update any entity and execute command php app/console doctrine:schema:update it is only updating the postgresql public schema.
How can we update all schemas in postgres with command?

You can create multiple entity managers in your config file. Afterwards you can update any scheme what you want. Let's assume that you have two entity manager: foo foo and bar . Then following command will update related schemas:

 php app/console doctrine:schema:update --force --em=foo
 php app/console doctrine:schema:update --force --em=bar

Symfony has nice documentation about it.

Probably a "too late" answer, but Doctrine will let you simply specify PostgreSQL schema in the Table annotation :

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(schema: 'name')] // <-- whatever schema you need here.
class Entity {
    //...
}

I found it to work reasonably well everywhere but automatically generated migrations. For some reason the schema tool does not insert the custom schema into index name, so down migrations involving index removal fail complaining about non-existing index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM