foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Allow to reset many databases in migrate mode

Open MatTheCat opened this issue 1 year ago • 9 comments

When orm.reset.mode is migrate , the ORMDatabaseResetter will simply run doctrine:migrations:migrate. This makes impossible to use this mode when you have migrations for many dtabases.

Could this library provide a configurations option so that each of its values is passed to doctrine:migrations:migrate’s --configuration option?

MatTheCat avatar Aug 09 '24 11:08 MatTheCat

Hi @MatTheCat

this is totally doable, but only in v2 (you mentioned you were using v2 in a previous issue)

nikophil avatar Aug 09 '24 12:08 nikophil

I'm wondering what's the best approach. I've never used this --configuration option. Is it the same file than the one in config/packages/doctrine_migrations.php (this one?). If so, shouldn't be already loaded as soon as the kernel boots?

nikophil avatar Aug 09 '24 12:08 nikophil

Yes it is the same, but a configuration file is limited to one connection/entity manager. That’s why you need the --configuration option when you have many: to select the right one.

In the ResetDatabase trait’s case, you’d loop over them to run doctrine:migrations:migrate for each configuration.

MatTheCat avatar Aug 09 '24 12:08 MatTheCat

ho OK, I missed the plural :)

Maybe we could update Foundry's config this way? WDYT?

    orm:
        reset:
            connections
                - default
            entity_managers:
                - default
            mode:  schema # or "migrate"
+          migrations:
+              configurations: [ '/path/to/config.php' ]

ping @kbond

nikophil avatar Aug 09 '24 12:08 nikophil

Honestly I don’t know :sweat_smile:

We need the connections option whatever the mode, but entity_managers is specific to schema, while configurations would be specific to migrate, right?

MatTheCat avatar Aug 09 '24 12:08 MatTheCat

to be totally honest, I was thinking we were passing the ems and/or the connections to doctrine:migrations:migrate, but we actually don't.

I'm not using this reset mode at all, and I don't think I've had to use migrations which deal with several em and/or connections, so I'm a little bit lost :shrug:

I think that passing --em or --conn options to doctrine:migrations:migrate would be a mistake, since it would run twice the same migration on different connections.

So at the end I think that both entity_managers and connections are specific to schema. And the new configurations you want would be specific to migrate.

Then, the ideal configuration would be:

    orm:
        reset:
           mode:  schema # or "migrate"
           migrate:
               configurations: [ '/path/to/config.php' ]
           schema:
               connections: [ 'default' ]
               entity_managers: [ 'default' ]

As a first step, we can only add orm.reset.migrate.configurations, and some day I'll deprecate orm.reset.{connections, entity_managers} in favor of the ones specific to schema.

FYI, we have a lot of specific demands around the reset database mechanism, I think at some point I'll rework it so that user can override some parts, thanks to decoration

nikophil avatar Aug 09 '24 13:08 nikophil

Seems like connections are only used to reset the database, not the schema :thinking:

But yeah keeping BC probably means adding a orm.reset.migrate.configurations anyway :+1:

MatTheCat avatar Aug 09 '24 13:08 MatTheCat

for the schema, we're using all entity_managers given, which makes sense: from the EM you can guess the related connection

nikophil avatar Aug 09 '24 13:08 nikophil

BTW, I'm on holidays this evening, and I cannot do it today. Feel free to provide a PR, but I won't be able to review before 2 weeks

nikophil avatar Aug 09 '24 13:08 nikophil