Skip to content

Commit

Permalink
CoreInstaller.php: drop foreign keys instead of ignoring them
Browse files Browse the repository at this point in the history
More cross-platform solution.
  • Loading branch information
adriendupuis committed Feb 20, 2025
1 parent 7c87e0f commit 1a22a87
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/bundle/RepositoryInstaller/Installer/CoreInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,20 @@ protected function getDropSqlStatementsForExistingSchema(
AbstractPlatform $databasePlatform
): array {
$existingSchema = $this->db->getSchemaManager()->createSchema();
$statements = ['SET FOREIGN_KEY_CHECKS=0'];
$statements = [];
// reverse table order for clean-up (due to FKs)
$tables = array_reverse($newSchema->getTables());
// cleanup pre-existing database
if ($databasePlatform->supportsForeignKeyConstraints()) {
// cleanup pre-existing database: drop foreign keys
foreach ($tables as $table) {
if ($existingSchema->hasTable($table->getName())) {
foreach($this->db->getSchemaManager()->listTableForeignKeys($table->getName()) as $foreignKeyConstraint) {
$statements[] = $databasePlatform->getDropForeignKeySQL($foreignKeyConstraint->getName(), $table->getName());
}
}
}
}
// cleanup pre-existing database: drop tables
foreach ($tables as $table) {
if ($existingSchema->hasTable($table->getName())) {
$statements[] = $databasePlatform->getDropTableSQL($table);
Expand Down

0 comments on commit 1a22a87

Please sign in to comment.