Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to register migrations from multiple folders #204

Closed
jjanvier opened this issue Feb 4, 2015 · 15 comments · Fixed by #238
Closed

Be able to register migrations from multiple folders #204

jjanvier opened this issue Feb 4, 2015 · 15 comments · Fixed by #238
Milestone

Comments

@jjanvier
Copy link

jjanvier commented Feb 4, 2015

Hello Doctrine team,

At Akeneo, our migrations are stored in different folders (yes, we really need that). Would you be interested a PR that allows this feature ? Basically it seems that only the class Doctrine\DBAL\Migrations\Configuration\Configuration should be modified.

@jjanvier jjanvier changed the title Be able Be able to register migrations from multiple folders Feb 4, 2015
@NigelGreenway
Copy link

+1 for this.

I have been looking at the best way of doing this myself.

@jjanvier Out of interest, how do you separate yours? At the moment I have been looking at connection/release/versionxxxxxxxx.php

@chrisguitarguy
Copy link
Contributor

@mikeSimonson I can help with this! Just need to know how you would want this to work? Just glob multiple directories for Version*.php? Or does there need to be separate namespaces?

I would think the namespace wouldn't matter. Just recursively search the directory, require_once every file, and look for all the classes from the directory filtering out the ones that don't extend AbstractMigration. Similar to what the doctrine persistence annotation driver does.

@mikeSimonson
Copy link
Contributor

I would like to know why @jjanvier and @NigelGreenway need that feature to find the best way to do it.

If it's to have a folder to keep older migration, it make sense to me.
We wouldn't need to change the namespace and a simple recursive glob would work.

Is it what they are looking for ?

@chrisguitarguy
Copy link
Contributor

I can think of a good reason for multiple directories and removing the namespace: integration with framework modules or bundles. Each one could hook it and register their own migrations.

@NigelGreenway
Copy link

The way I would like to use it is to separate them by feature, this way it would only be an extra level of directories.

Sorry I can do anything myself at the moment.

@mikeSimonson
Copy link
Contributor

Separating by feature looks like a valid use case too but the multi integration does not. The migration are going to be different anyway, it makes more sense to have different folder and different config for different integration IMO.

@chrisguitarguy
Copy link
Contributor

Would this require recursively searching a single directory? Or being able to register multiple directories in the config? Maybe both?

@mikeSimonson
Copy link
Contributor

I think that we can probably get away just searching recursively the folder. The question is should we add an option to keep the old behavior ?

@chrisguitarguy
Copy link
Contributor

I was going to pull out the "find and load files" stuff into a separate class, so if someone wanted to go back to the old behavior they could inject the old class into their configuration when creating the commands. Should be able to keep things compatible, so it should be transparent.

@stof
Copy link
Member

stof commented May 4, 2015

Well, registering migrations from bundles would cause issues with the sorting of migrations: bundle migrations should be triggered based on the date at which the bundle was updated in the project bringing this migration, not based on the date the migration was added in the bundle. Otherwise it could break other existing migrations of the project (which would suddently run with the new bundle schema while they were written for the old one).
This is why registering migrations from bundles is not implemented in DoctrineMigrationsBundle: doing it is broken by design.

@chrisguitarguy
Copy link
Contributor

@stof good call. Didn't think about that.

I'm too used to the migrations in Django, which are on a per-app basis.

@stof
Copy link
Member

stof commented Aug 3, 2015

@chrisguitarguy and this is what DoctrineMigrationsBundle is doing too. But a Symfony project is an app (you can actually have multiple apps if you have multiple kernels by duplicating the app folder to create another app). Symfony bundles are not apps.

@chrisguitarguy
Copy link
Contributor

Django apps are pretty much along the lines of what a Symfony bundle is: a reusable piece of functionality. Symfony has bundles and an application. Django has apps and sites.

Django batteries included-ness means everyone uses an ORM and the core table naming logic makes sure database conflicts don't happen between apps. Django can guarantee each app's migrations won't cause issues with other things.

To do migrations per bundle, Bundle's would need a way to "claim" tables and such to make sure nothing else messed with them. Schema object abstractions would probably have to be used and no more addSql. All that sounds like a big pain in the ass to implement and deal with, so I can understand the reasoning.

@stof
Copy link
Member

stof commented Aug 3, 2015

@chrisguitarguy this would work if bundles were fully isolated from each other. But it is very common for bundles to have relations to tables of other bundles, or for the actual entity to be in the project itself, extending from a base class in the bundle, to allow adding extra fields.
And this does not change the fact that queries added at the project level may depend on fields coming from bundles.

And using the Schema object abstraction to write your migration is already possible (and causing a huge performance issue for anyone not using this feature btw, see #323 about that). But as I already explained several times (for instance in #79 (comment)), this has major drawbacks and is totally unsuited for production usage, because a production migration requires to migrate both the schema and the existing data. Running migrations on an empty database is not a real use case for production.

@goetas
Copy link
Member

goetas commented Apr 18, 2020

As of doctrine migrations 3.0 this is supported out of the box. I wrote a tutorial about it on https://www.goetas.com/blog/multi-namespace-migrations-with-doctrinemigrations-30/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants