Behat / CommonContexts

Common FeatureContext classes for Behat
116 stars 34 forks source link

Why not truncate tables instead of dropping and recreating schema? #48

Open natelenart opened 10 years ago

natelenart commented 10 years ago

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;');
yoanmLf commented 4 years ago

+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.