Created
October 2, 2013 10:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctrine: | |
dbal: | |
platform_service: postgresql_platform | |
services: | |
postgresql_platform: | |
class: Acme\DBAL\Platforms\PostgreSqlPlatform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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':''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!