Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine schema:update generates the same SQL again and again

Running bin/console doctrine:schema:update --force again and again, it always output 39 queries executed even after clearing cache/restarting php-fpm. So it always execute the same SQL requests again and again...

The SQL looks likes (from --dump-sql)

ALTER TABLE apply_queue CHANGE cv_id cv_id INT DEFAULT NULL, CHANGE team_id team_id INT DEFAULT NULL;
....

And a lot of lines similar to this.

The ApplyQueue class look like:

/**
 * AppBundle\Entity\ApplyQueue.
 *
 * @ORM\Entity(repositoryClass="AppBundle\Entity\ApplyQueueRepository")
 * @ORM\Table(name="apply_queue")
 */
class ApplyQueue
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Cv")
     * @ORM\JoinColumn(name="cv_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $cv;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Team")
     * @ORM\JoinColumn(name="team_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $team;

    ...

}

DBAL config :

doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
        types:
            json: Sonata\Doctrine\Types\JsonType
            review_status: AppBundle\Model\Enum\ReviewStatusEnumType
        mapping_types:
            review_status: string

The structure of the table:

enter image description here

This is an "old" project that has been upgraded to Symfony 3.4 and MariaDB 10.2.

Thanks

like image 839
sf_tristanb Avatar asked Nov 11 '17 21:11

sf_tristanb


People also ask

Why are changes to my schema not replicated in Azure SQL database?

If you are making a change in a SQL Server database, make sure the schema change is supported in Azure SQL Database. If schema changes are made in databases other than the database where the DDL trigger is created, the changes are not replicated. To avoid this issue, you can create DDL triggers to block changes on other endpoints.

How do you update a database schema without downtime?

In reality, when you’re working with one of these legacy databases, updating the schema without downtime usually requires creating a complete replica of your data so that you can operate in parallel. This allows you to update the schema in the replica and then gradually migrate your application over to it.

How do I make schema changes in Azure SQL database?

You can only make schema changes in the database where the DDL trigger is created. If you are making a change in a SQL Server database, make sure the schema change is supported in Azure SQL Database. If schema changes are made in databases other than the database where the DDL trigger is created, the changes are not replicated.

How do I avoid replicating schema changes made under schema datasync?

This example adds a filter to avoid replicating schema changes made under schema DataSync, because these are most likely made by the Data Sync service. Add more filters if you only want to replicate certain types of schema changes. You can also add more triggers to replicate other types of schema changes.


1 Answers

MariaDB 10.2 is not yet supported by Doctrine, causing this problem.

See linked PR : https://github.com/doctrine/dbal/pull/2825

like image 94
sf_tristanb Avatar answered Nov 15 '22 10:11

sf_tristanb