FrozenDependencies exception when using multiple migration configurations with ResetDatabase in mode: migrate
I'm encountering an issue when using ResetDatabase trait with multiple Doctrine migration configuration .yaml files in mode: migrate.
I have multiple .yaml migration configuration files — one for each entity manager and corresponding database:
zenstruck_foundry:
orm:
reset:
mode: migrate
migrations:
configurations:
- './config/migrations/database1.yaml'
- './config/migrations/database2.yaml'
Each configuration specifies a different em and migrations_paths
The Problem
When the first migration is executed, it runs successfully. However, on the second configuration, I get Doctrine FrozenDependencies exception: The dependencies are frozen and cannot be edited anymore.
Full error message from my logger:
{
"message": "Error thrown while running command \"doctrine:migrations:migrate --configuration='./config/migrations/database2.yaml' --no-interaction\". Message: \"The dependencies are frozen and cannot be edited anymore.\"",
"context": {
"exception": {
"class": "Doctrine\\Migrations\\Exception\\FrozenDependencies",
"message": "The dependencies are frozen and cannot be edited anymore.",
"file": "/app/vendor/doctrine/migrations/src/Exception/FrozenDependencies.php:13"
}
}
}
It appears that the internal container dependencies for migrations are frozen after the first migration, so when it attempts to run the second, it fails due to immutability.
I expected Foundry to sequentially run all listed migration configurations (each with its own entity manager) during database reset in test environment.
Is there a way to reset multiple databases using migration mode with separate config files for each? Or does this require some workarounds?
Hmm, I've never seen that exception before. I don't have experience with a non-out-of-the-box migration setup. Does it have anything to with https://github.com/doctrine/migrations/issues/1440?
yeah it seems totally related. Or at least to https://github.com/doctrine/migrations/pull/1432
I've never seen this exception neither... I'll try to reproduce in our testsuite and see what can be done
OK, I do think this should be fixed in doctrine/migrations, see https://github.com/doctrine/migrations/issues/1502
I've created a failing test case in our testsuite: https://github.com/zenstruck/foundry/pull/892
let's see what will be the answer in my issue in their repo...
We're facing the same problem.
We still encounter the issue even when commenting on our postUp.
Any updates?
Hi
this is a problem in doctrine/migrations repo
see https://github.com/doctrine/migrations/issues/1502
the dependencies need to be "unfrozen" after the migrations has ran - sorry, I'm running out of time to work on this. If you're willing to make a PR there, please notify us here, so we can fix and merge https://github.com/zenstruck/foundry/pull/892
this was fixed here https://github.com/zenstruck/foundry/pull/892
we'll also need https://github.com/doctrine/migrations/pull/1528 to be accepted
any chance any one concerned by this problem could test it in a real world project?
Hi
We tested this with a project that had migrations across multiples databases. Ex:
# config/packages/migrations/app_one.yaml
em: app_one
migrations_paths:
'DoctrineMigrations\AppOne': 'migrations/appOne'
# config/packages/migrations/app_two.yaml
em: app_two
migrations_paths:
'DoctrineMigrations\AppTwo': 'migrations/appTwo'
We encountered a problem. The connection is maintained when the second migration command is executed.
In the initialize method of DoctrineCommand, the dependencyFactory is already init and only the configurationLoader is set, not the connectionLoader.
@kells64000 do you have the same error than the original post?
if not, please open a new issue. anyway, I think https://github.com/doctrine/migrations/pull/1528 needs to be merged before this feature could ever work 🤷
Indeed, I no longer have the frozen migration problem.
I will open a new issue that is more specific to our behaviour.