A small symfony doctrine migration improvement task

Doctrine migration allows to easily migrate database schema by running a set of migration files. Let's say you have to run 10 migrations files, doctrine is going to run each files and once it is done, the migration version will be updated.

However if an error occurs, you will be in a very bad situation :

  • you don't know which migration failed
  • you cannot rollback your changes as migration number is not updated
  • the task does not display which migration is running

I have created a patch to fix this situation : http://trac.symfony-project.org/ticket/8728.

In the meantime, I have add a new task in my swToolbox plugin (http://github.com/rande/swToolboxPlugin)

run the task :

  ./symfony sw:doctrine-migrate

output :

  awesome-project thomas$ ./symfony sw:doctrine-migrate
  >> doctrine  Migrating from version 134 to 136
  >> doctrine  executing migration : 135, class: Version135
  >> doctrine  executing migration : 136, class: Version136
  >> doctrine  Migration complete

The new task runs the set of migration one by one, updating the migration version after each migration. So If one migration fail, you will be able to react quickly to solve the problem.

Comments

Christopher Shennan
about 3 hours after
This is a problem I've faced frequently, especially when building migrations on a development site and in the past I've got around this by backing up the database prior to building the migrations, restoring the database each time something goes wrong, isolating and fixing the issue and trying again. While this works ok on the development site, this is a far from ideal solution when you move to a QA or live site.

This can obviously have several iterations until you get the migrations working correctly and I really welcome this new task as I can see it making building migration and troubleshooting them much easier.

Many Thanks.

Chris Shennan
Lukas
3 days after
honestly there are two scenarios:
1) your RDBMS supports transactional DDL like PostgreSQL .. in this case Doctrine should be able to do a clean rollback automatically
2) in all other cases you really should do a manual backup before running migrations

but showing the migration that is currently running is indeed a nice touch in order to later be able to more easily figure out which migration needs to be fixed.
NicoD.
6 days after
This is an excellent idea that should be very helpful when a migration fails.

Thanks a lot !
benjamin grandfond
about 1 month after
Thanks a lot for this task which saved my day !

Add comment











A la recherche de projets symfony ?

Tags

Last posts