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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With