Shailesh Daund
Shailesh Daund

Reputation: 180

How to update multiple schema in PostgreSQL with Symfony & Doctrine ORM

We have a Symfony (v2.x, although the question applies to all Symfony versions until at least v6.x) project using Doctrine ORM (v2.x).

We managed to connect to PostgreSQL with multiple schemas in a single database.

Now when we update any entity and execute the command php app/console doctrine:schema:update it is only updating the PostgreSQL's public schema.

How can we update all schemas in PostgresSQL?

This question to all versions of Symfony, until at least 6.x line.

Upvotes: 0

Views: 1135

Answers (2)

Jan Klan
Jan Klan

Reputation: 884

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.

Upvotes: 1

Zamir
Zamir

Reputation: 441

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.

Upvotes: 0

Related Questions