5

Running php app/console doctrine:migrations:diff generates a new migration class as required to translate the current database schema to that specified by changes to entities.

This example shows such a generated class for creating a fos_user table:

class Version20120712145445 extends AbstractMigration
{
    public function up(Schema $schema)
    {
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");        
        $this->addSql("CREATE TABLE fos_user (id INT AUTO_INCREMENT NOT NULL, ...);
    }

    public function down(Schema $schema)
    {
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");        
        $this->addSql("DROP TABLE fos_user");
    }
}

As you can see, this the generated migration is tied to a specific database server, that being MySQL in this instance.

I'd like to use an in-memory sqlite database in test environments due to the (expected) performance benefits reducing test execution time.

I could take the above generated SQL and translate that into $table = $schema->createTable(); $table->addColumn(); equivalents, however doing so is both time consuming and invites the introduction of errors due to a poor human translation of SQL to code.

Can the doctrine:migrations:diff command create platform-agnostic migration code instead of the above platform-specific SQL?

Jon Cram
  • 16,609
  • 24
  • 76
  • 107
  • I think the answer is no, not yet... And anyway, the diff tool should only be a nice-to-have and should not avoid the developer to write himself his migration classes. But still, I agree that this would be a nice feature. – Nanocom Jul 23 '12 at 21:05

2 Answers2

3

No, that is not possible with the current versions. If you need database agnostic migrations you should take a look at LiquiBase for migrations. There is a Symfony2 Bundle for LiquiBase too LiquibaseBundle

Timo Haberkern
  • 4,409
  • 2
  • 27
  • 41
2

Currently there is no support for other database migration tools but they are planning to support some database management tools

see doctrine: DBAL-602 this ticket is a feature-request for LiquiBase, DBDeploy and phinx support for doctrine migrations

acrobat
  • 2,179
  • 2
  • 27
  • 35