Diff won't run with a custom list of migrations
Pictor13 opened this issue · 3 comments
Hi everyone,
Is it normal that when I use the migrations
option, to specify a custom order/naming for my migrations, I loose the ability to use doctrine:migrations:diff
?
I have a factory in order to provide dependencies, and a custom list of migrations:
doctrine_migrations:
services:
'Doctrine\Migrations\Version\MigrationFactory': 'App\VersionFactory'
migrations:
migration1: App\Migrations\Version20191120170359
migration2: App\Migrations\Version20191127162437_RemoveField
migration3: App\Migrations\Version20201210214842_RenameField
migration5: App\Migrations\Version20190524121231
Running doctrine:migrations:diff
fails:
In DiffCommand.php line 127: assert(is_string($namespace))
There's no configured namespace indeed. If I add one with
migrations_paths:
'App\Migrations': '%kernel.project_dir%/src/Migrations'
and try :diff
again it now sees a double registration in the container
(probably either via autoretrieve of migration_path
and via the migrations
custom definition):
Migration version App\Migrations\Version20191120170359 already registered with class App\Migrations\Version20191120170359
services.yaml
already excludes the migration folder:
App\:
resource: '../src/*'
exclude: '../src/{Controller,DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
How can I still retain the diff
ability having a custom-name migration list?
In order to run a diff command, we need to know in which namespace and path save the result, thus we need the migrations_paths
option.
on the other hand, as soon as you specify the migrations_paths
option, this library will try to load the classes defined in there.
what is the expected behavior here? what feature are you asking here and how should it work?
Thanks for clarifying.
As mentioned on the last line, I want to keep using the bundle as usual and profit from features like the doctrine:migrations:diff
, but being at the same time able to specify a custom order & meaningful naming for the migrations.
I would expect to be able to configure the bundle with a custom migration list, without losing features on the way.
Like, in my case, the useful DiffCommand
that resolves schema changes automatically, and generates the migration and the SQL for the up()
and down()
methods.
let me rephrase your ask.
you would like to specify explicitly the migrations, to be able to run the diff command, but to avoid loading the migrations found in the migrations folder, right? if is so, you can:
- specify a path with no migrations in there
migrations_paths:
'App\Migrations': '%kernel.project_dir%/src/SomeOtherMigrationsPath'
with this solution the diff
will be generated in %kernel.project_dir%/src/SomeOtherMigrationsPath
but you will have to move them in src/Migrations
probably
- override using the symfony DI the
\Doctrine\Migrations\Finder\MigrationFinder
service, returning always an empty array and rely on autoloading to load the migration classes.
# config/packages/doctrine_migrations.yaml
doctrine_migrations:
services:
'Doctrine\Migrations\Finder\MigrationFinder': 'my.migrations.finder'
# config/services.yaml
services:
my.migrations.finder:
class: SomeCutomImplOfMigrationFinder
- I'm not sure if it makes sense to include a new feature in this bundle to avoid loading the migrations explicitly, something like
# config/packages/doctrine_migrations.yaml
doctrine_migrations:
do_not_load_migrations: true