Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - Can doctrine:migrations:diff create DB-agnostic code instead of SQL?

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?

like image 943
Jon Cram Avatar asked Jul 23 '12 16:07

Jon Cram


2 Answers

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

like image 116
Timo Haberkern Avatar answered Nov 15 '22 09:11

Timo Haberkern


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

like image 39
acrobat Avatar answered Nov 15 '22 07:11

acrobat