migrations icon indicating copy to clipboard operation
migrations copied to clipboard

$plannedSql shared between commands execution.

Open R3VoLuT1OneR opened this issue 11 months ago • 0 comments

Bug Report

Used version 2.x now after migration to 3.x I am found this problem. I am using doctrine migration in my PHPUnit test suite.

On each setUp I am running running migration:

migrations:migrate

And then in each tearDown I have:

migrations:migrate first

In my migration up method I have some INSERT SQL queries. In my down I have only DROP TABLE.

Q A
BC Break yes
Version 3.7.2

Summary

Basically executed queries shared between commands, if we reuse the "Application".

It's happens because migration objects kept in memory and $plannedSql is not clear between commands execution. So migration executor appends new queries from down function to $plannedSql and then executes queries from prev up function call and later queries from down call.

Current behavior

On the doctrine:migrate first running in the tearDown the INSERT from the up method executed and after that the DROP TABLE exectued.

How to reproduce

$configuration = new Configuration();
$configuration->addMigrationsDirectory(
    'App\Migrations',
    __DIR__ . '/migrations'
);

$dependencyFactory = DependencyFactory::fromConnection(
    configurationLoader: new ExistingConfiguration($configuration),
    connectionLoader: new ExistingConnection(static::connection()),
);

$migrationsApplication = ConsoleRunner::createApplication(
    dependencyFactory: $dependencyFactory
);

$migrationsApplication->setAutoExit(false);

// Migration
$migrationsApplication->run(new StringInput('migrations:migrate --no-interaction'));

// Rollback
$migrationsApplication->run(new StringInput('migrations:migrate first --no-interaction'));

Expected behavior

No SQL quries from the first migrations executed on migrations:migrate first, only DROP TABLE no INSERT.

R3VoLuT1OneR avatar Feb 29 '24 13:02 R3VoLuT1OneR