I have a single data connection with two schemas configured in my Symfony 6 project:
Localhost
- app
- common
<doctrine:config>
<doctrine:dbal dbname="app" url="%env(resolve:DATABASE_URL)%">
</doctrine:dbal>
Both schemas have a separate set of entity mapping.
- The
app
has mapping written in XML files. It's the old one. - The
common
has mapping written using attributes. It's the new one. I was trying to create the first SQL table for it.
I have entity manager configured this way:
<doctrine:orm
default-entity-manager="default"
auto-generate-proxy-classes="true"
>
<doctrine:entity-manager
name="default"
connection="default"
naming-strategy="doctrine.orm.naming_strategy.underscore_number_aware"
auto-mapping="false"
>
<doctrine:mapping
name="App"
alias="App"
prefix="App\Entity"
is-bundle="false"
type="xml"
dir="%kernel.project_dir%/config/doctrine"
/>
<doctrine:mapping
name="ModelCommon"
alias="ModelCommon"
prefix="MyCompany\ModelCommon\Entity"
is-bundle="false"
type="attribute"
dir="%kernel.project_dir%/model/Entity"
/>
</doctrine:entity-manager>
</doctrine:orm>
So here's the issue. The project before had only the app
schema. So the database contains a couple of already integrated entities. I want to integrate the other common
schema having only one entity (for now). I have issues with generating a proper migrations for it.
This is the new entity:
namespace MyCompany\ModelCommon\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'category', schema: 'common')]
class Category
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
private ?int $category_id = null;
#[ORM\Column(type: 'string')]
private string $category_name;
}
Whenever I'm trying to doctrine:migrations:diff
or just doctrine:schema:update --dump-sql
, I receive this information:
[OK] Nothing to update - your database is already in sync with the current entity metadata.
Obviously, removing schema: 'common'
from the entity results in proper query generated:
CREATE TABLE category (category_id INT AUTO_INCREMENT [...]
I've already tried to manage the issue on multiple ways. Like, making a separate <doctrine:connection ... />
or separate entity managers (one for each schema). Both ideas failed. Even with changing dbname="app"
for default_dbname="app"
in the DBAL configuration.
It would be even ideal to have two separate namespaces of migrations which would have no affect on each other. Like, migrating one schema would consider only one namespace. Though I had problems with implementing that idea as well.
Is there any particular way on how to manage with this problem? Thank you in advance for any help .