Skip to content

Instantly share code, notes, and snippets.

@tiraeth
Created October 2, 2013 10:29
Show Gist options
  • Save tiraeth/6791733 to your computer and use it in GitHub Desktop.
Save tiraeth/6791733 to your computer and use it in GitHub Desktop.
How to override default platform in Doctrine2 with Symfony2. Example: Force RESTART IDENTITY for TRUNCATE in PostgreSQL when used in "test" environment. This will help you with functional tests as you will always have the same ids.
doctrine:
dbal:
platform_service: postgresql_platform
services:
postgresql_platform:
class: Acme\DBAL\Platforms\PostgreSqlPlatform
<?php
namespace Acme\DBAL\Platforms;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform as DoctrinePostgreSqlPlatform;
class PostgreSqlPlatform extends DoctrinePostgreSqlPlatform
{
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE '.$tableName.' RESTART IDENTITY '.(($cascade)?'CASCADE':'');
}
}
@podorozhny
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment