0

Environnement:

  • php 8.1
  • symfony 5.4
  • doctrine/dbal 3.3
  • doctrine/doctrine-bundle 2.7
  • doctrine/migrations 3.5.1
  • postgresql 14.4

My problem is the following; We have a database containing several schema to separate the data useful to the system and those published directly to users. We use of course the classic entity declaration with Symfony & Doctrine:

/**
 * @ORM\Table(name="stats", schema="system")
 * @ORM\Entity(repositoryClass="App\Repository\System\StatsRepository")
 */
class Stats

The problem is that when we delete a relation between the public schema and the system schema, the migration generated by the command bin/console doctrine:schema:update has an error when deleting the index. Here is the migration generated:

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('DROP INDEX idx_2225600edc6d4b4b');
        $this->addSql('ALTER TABLE system.stats DROP article_id');
    }

The problem being that in deleting the index, the line forgets to specify that the index comes from the system schema. We need:

$this->addSql('DROP INDEX system.idx_2225600edc6d4b4b');

We want to keep the bin/console doctrine:schema:update operation for updating the database, but this problem now forces us to use the migration system to change the drop index.

I know that the obvious solution would be to use the migration system (bin/console make:migration) but this implies some changes in the IC. That's why I'm wondering; have you ever had this problem? If yes, how did you solve the problem?

MarquandT
  • 11
  • 2
  • Is explicit index declaration is fine for your project codebase? If yes, then try to add index to @ORM\Table(..., indexes={@ORM\Index(name="idx_...", columns={"stats"})}) or maybe just as another annotation @ORM\Index(name="idx_2225600edc6d4b4b", columns={"stats"}). And, maybe, it's better to use attributes with 8.1: #[ORM\Index(name: 'idx_...', columns=['stats'])] – yaroslavche Sep 28 '22 at 19:35
  • @yaroslavche, I tried adding the declaration of the index in the entity, it does not cause any modification on the migration or the update of the database – MarquandT Oct 03 '22 at 07:25

0 Answers0