Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
natelenart opened this issue Oct 4, 2013 · 1 comment
Open

Comments

@natelenart
Copy link

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
Copy link

yoanmLf commented Apr 22, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants