doctrine/DoctrineMigrationsBundle

Allow explicitly setting default namespace or path for generated migrations

rimas-kudelis opened this issue · 8 comments

Some packages, such as Sylius Plus, use $container->prependExtensionConfig() to add their migration namespaces to the list. This causes their migration paths to appear before the paths configured in the app, making their first path the default for newly generated migrations:

Generated new migration class to "/var/www/vendor/sylius/plus/src/DependencyInjection/../Migrations/Version20210819084746.php"

This is undesired and annoying, and it seems the only ways to override this at the moment are for the app developer to either specify the namespace when running bin/console d:m:diff, or to resort to prependExtensionConfig() as well.

Thus I'd like to suggest a new parameter, which would allow explicit configuration of the default generated migration path or namespace.

You can pass the --namespace parameter for both diff and generate commands. The namespace will be used to generate the migration file and the file will be saved in the path configured for that namespace.

You can pass the --namespace parameter for both diff and generate commands. The namespace will be used to generate the migration file and the file will be saved in the path configured for that namespace.

Yes I know that, I even mentioned that in my initial post.

I was talking about an ability to configure the default, so that I don't have to explicitly use --namespace each time I want to generate a diff.

isnt' enough to place it as first in the config file?

That's precisely what I'm asking for. Is it possible already?

i guess so, I did not try it personally

Well, I could not find an option for this when I looked, and the code didn't seem to have any support for this either, that's why I filed this request.

I'm not sure if this request should better be filed under Doctrine/Migrations as opposed to the MigrattionsBundle, but I'm pretty certain that it's not being fulfilled at the moment.

The affected Command code is here which is why I'm not sure which repository to file this under. Assuming this bundle is mostly about configuratio though, the request doesn't seem misplaced to me.

One way to handle this functionality in this bundle would probably be to use a compiler pass to rearrange the configured migration namespaces, putting the configured "default" one first?

Yes, I did.
Like I said in my initial comment, the problem is that sometimes third party packages use prependExtensionConfig(), which causes their paths to precede user's specified paths.
I don't know why Sylius Plus uses this particular method of adding its migrations, but only the way I found to work around this inconvenience was to write my own class implementing PrependExtensionInterface to make sure that our App\Migrations namespace is the first in the list. It would have been much nicer if I could just specify the default namespace in the config explicitly.