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

IBX-9617: Fixed DB schema reinstallation #485

Open
wants to merge 6 commits into
base: 4.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$schemaManager = $this->connection->getSchemaManager();
if (!empty($schemaManager->listTables())) {
$io = new SymfonyStyle($input, $output);
if (!$io->confirm('Running this command will delete data in all Ibexa generated tables. Continue?', )) {
if (!$io->confirm('Running this command will delete data in all Ibexa generated tables. Continue?', false)) {
return 0;
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/bundle/RepositoryInstaller/Installer/CoreInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,18 @@ protected function getDropSqlStatementsForExistingSchema(
): array {
$existingSchema = $this->db->getSchemaManager()->createSchema();
$statements = [];
// reverse table order for clean-up (due to FKs)
$tables = array_reverse($newSchema->getTables());
// cleanup pre-existing database
$tables = $newSchema->getTables();
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());
}
}
}
}
Comment on lines +102 to +112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels to me like a workaround. Tables should be dropped in a correct order. Have you tried to see if we can reorganize tables order in Yaml for doctrine schema instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alongosz I didn't. I replaced the not-working array_reverse trick with another trick.
Studying how the table list is loaded/built from YAML schema is probably also necessary to understand why 3 tables are missing. But my knowledge of Doctrine is limited and I don't manage to explore this schema declaration.

// cleanup pre-existing database: drop tables
foreach ($tables as $table) {
if ($existingSchema->hasTable($table->getName())) {
$statements[] = $databasePlatform->getDropTableSQL($table);
Expand Down
Loading