0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

No worries. You're probably right: the title is misleading because of the ancient Symfony version, but the problem and solution apply to every single version of Symfony, including the current 6.2.
0

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.

1 Comment

Zamir thanks for your reply. We have a single PostgreSQL database with multiple schemas. Whatever you have suggested, that we already implemented in another project that require multiple database connections (multi tenant).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.