-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Container aware migrations #28
Conversation
This would allow much more powerful migrations as right now all you can do is SQL stuff. Moved from https://github.com/symfony/DoctrineMigrationsBundle/pull/2
This would be most helpful |
big 👍 |
There may be an issue with how this patch calls The call is being made from a static method and can result in a "Using $this when not in object context;" fatal error. It does for me, whether it does for all may be a matter of configuration. Changing the call to Would this matter affect others? If so, should the above changes be made, this pull request closed and a new pull request made? |
@webignition solved, thanks for noting this! |
Would it be best practice to access the container in a Doctrine migration? Say I have 3 fields to store a date
The other solution is to write 2 doctrine migration and a custom command, and run them in that order: migration that add the field |
@qpleple I would stick with SQL in your example as all you need is already in the database and accessing the container doesn't give you much. This PR has in mind other cases like updating your database with data from external sources or from logic scattered all over your services. |
@frosas Yes, I know my toy example can be done only in SQL. I was asking about the idea of indeed having to use some logic of the application in the migration in order to chain migrations without worrying about running custom commands between them. |
@qpleple oh yes, this is the main point, to completely automate the deploys :) |
@frosas What can container aware migrations achieve that Doctrine Fixtures don't? |
@webignition fixtures can do the job to initialize the database but what about later? |
@frosas I agree entirely, I asked merely because this might be a question raised by the maintainers. I'm currently using a container-aware fork of DoctrineMigrationsBundle and use the postUp() and postDown() methods to inject essential data in ways that fixtures can't. |
@frosas I agree |
I came looking for this because I have a legacy database where times are stored using the user's timezone, which is stored next to it in the database. Converting the existing date/time values can't be done with simple SQL. I need to
Without access to the container i'm going to have to create multiple database migrations and remember that I have to run a custom command that will only be used once between steps 1 and 2. I don't know much about DoctrineFixtures, but it doesn't appear to be what I need. |
We have been using doctrine container aware migrations lately and is important to consider the following scenario:
The only solution I can think of is running each migration synchronized with the source code it was created. The other possibility is to run the entity manager migrations at the end - but maybe some SQL migrations expect the data that those entity-manager migrations would modify - or maybe save and load the entity metadata snapshot with each migration??? |
That's a good point. Sounds like using Entities in migrations is dangerous and cumbersome. I think the better solution might be to expose a database connection to run SQL (or DQL?) directly. If DQL is bound to how your entities are defined it may have the same problem. I've chosen to use an external script that calls doctrine:migrations:migrate with one revision, then goes and runs other commands, then comes back to run doctrine:migrations:migrate to upgrade to the latest version. |
@diegosainz yes, this is a very good reason to stay in the lower layers in the migrations. What I've done in these cases is to create major versions (i.e. branches) of the code. When the changes in the code broke the migrations and fixing them was not worth the hassle I created a new version. |
Please look at #27 for working simple alternative approach. |
👍 |
This would allow much more powerful migrations as right now all you can do is SQL stuff.
Moved from https://github.com/symfony/DoctrineMigrationsBundle/pull/2