Symfony 2.1 Doctrine Migrations and Sluggable
Yesterday I had an annoying issue while adding a Sluggable behaviour to an existing entity in my Symfony 2.1 project.
The issue was simple: since the slug field should be defined as NOT NULL and my DB was full of existing records,  the migrations failed with a mysql #1062 - Duplicate entry due to the fact that all the existing records have, of course, the same empty value for the slug after its creation.

What I had to do was setting the slug field as NULLABLE, update the slugs, then set it to NOT NULL again.

So I thought of replicating the behavior of the Sluggable on the DBAL layer with custom queries, but this felt like reinventing the Sluggable's wheel, with too much checks to do (slug uniqueness, slugged fields, composition, etc).

So I decided to let a symfony command do the job for me.
I defined a service for recalculating the slugs: