A small symfony doctrine migration improvement task

1 / 9 / 2010

Small DX contributions always matter.

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.