CommonContexts icon indicating copy to clipboard operation
CommonContexts copied to clipboard

Why not truncate tables instead of dropping and recreating schema?

Open natelenart opened this issue 11 years ago • 1 comments

Disabling foreign key checks, truncating all tables and re-enabling foreign key checks is lightning-fast vs. the crawl of dropping and recreating all tables each time. What would be the downsides implementing this way?


# SymfonyDoctrineContext::buildSchema method

$connection = $entityManager->getConnection();
$connection->exec('SET FOREIGN_KEY_CHECKS = 0;');

$schemaManager = $connection->getSchemaManager();
$tables = $schemaManager->listTables();
foreach ($tables as $table) {
    $connection->exec(sprintf('TRUNCATE TABLE %s', $table->getName()));
}

$connection->exec('SET FOREIGN_KEY_CHECKS = 1;');

natelenart avatar Oct 04 '13 15:10 natelenart

+1

I also have an issue with the fact that schema is dropped an re-create because I use triggers to perform some tasks (mainly to create history for some table, stored inside an another table). As trigger are not managed by doctrine, they are not re-created when schema is re-created.

yoanmLf avatar Apr 22 '20 14:04 yoanmLf