doctrine/migrations — pull request #79 by tyler-sommer (2012-06-28 00:11:15+00:00)
Title: Make :migrations:diff smart and generate Schema object changes, not SQL directly

I refactored the way `DiffCommand` generates migrations, moving the SQL generation into `Migrations\Generator\SqlGenerator`.

I then created `PhpGenerator` that iterates over the given `SchemaDiff` and generates PHP code for the migration, using `DBAL\Schema` and related.

Usage (with symfony and MigrationsBundle): `app/console doctrine:migrations:diff --generator=php`

**There are a couple of hitches, though**: dropping indexes and dropping foreign keys.

`Table#dropIndex` was added in 2.2, but seeing as how migrations currently supports doctrine 2.0 and greater, I didn't want to rely on that.

So, the generator uses Reflection to get the `Table$_indexes` and `Table$_fkConstraints` property and then modify them. Terrible, I know, but I don't see a way around it.

I am thinking the generator should simply not support the removing of foreign keys. I've used this code exclusively for a production application for the past few months, and dropping foreign keys in MySQL requires careful ordering of the SQL commands. Modifying the Schema object doesn't really allow you to enforce an order, and much of the time it simply does not work-- complaining about "General error: 1025 Error on rename of ..."

As for dropping of indexes, I was thinking I could check the Doctrine version to see if `Table#dropIndex` is available, otherwise fallback to the reflection.

Thoughts?