Skip to content

Bug Report: Migrations are executed last because of incorrect Doctrine Migrations configuration #53

@LeNathanACSEO

Description

@LeNathanACSEO

When resetting the database from scratch, the plugin’s migrations are executed after all migrations, even when their version numbers are older.
This causes dependent migrations (e.g. custom ALTER TABLE monsieurbiz_homepage_homepage_translation ...) to fail because the base tables are not yet created.

This issue seems to be caused by the way the plugin currently prepends its doctrine_migrations configuration.

In MonsieurBizSyliusHomepageExtension, the plugin manually merges migration paths like this:

public function prepend(ContainerBuilder $container): void
{
    $doctrineConfig = $container->getExtensionConfig('doctrine_migrations');
    $container->prependExtensionConfig('doctrine_migrations', [
        'migrations_paths' => array_merge(array_pop($doctrineConfig)['migrations_paths'] ?? [], [
            'MonsieurBiz\SyliusHomepagePlugin\Migrations' => '@MonsieurBizSyliusHomepagePlugin/Migrations',
        ]),
    ]);
}

This manual merge breaks the expected migration order when multiple bundles or namespaces are involved.
Doctrine then loads the plugin’s migrations at the very end, regardless of their version number.

To fix that, replace the manual prepend logic with the PrependDoctrineMigrationsTrait, like it's done on the Block plugin:

use Sylius\Bundle\CoreBundle\DependencyInjection\PrependDoctrineMigrationsTrait;

final class MonsieurBizSyliusHomepageExtension extends Extension implements PrependExtensionInterface
{
    use PrependDoctrineMigrationsTrait;

    public function prepend(ContainerBuilder $container): void
    {
        $this->prependDoctrineMigrations($container);
    }

    protected function getMigrationsNamespace(): string
    {
        return 'MonsieurBiz\SyliusHomepagePlugin\Migrations';
    }

    protected function getMigrationsDirectory(): string
    {
        return '@MonsieurBizSyliusHomepagePlugin/Migrations';
    }

    protected function getNamespacesOfMigrationsExecutedBefore(): array
    {
        return [
            'Sylius\Bundle\CoreBundle\Migrations',
        ];
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions