From 3979af08cd0aa9f8f1e5a0c409ff3a9ca317fbbe Mon Sep 17 00:00:00 2001 From: PixoVoid Date: Tue, 3 Dec 2024 20:57:59 +0100 Subject: [PATCH] Update --- migration.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/migration.php b/migration.php index fac5064..eaa5aba 100644 --- a/migration.php +++ b/migration.php @@ -325,15 +325,27 @@ function createForeignKeyConstraints(PDO $pgsql, PDO $mariadb, string $tableName ADD CONSTRAINT `{$fk['constraint_name']}` FOREIGN KEY (`{$fk['column_name']}`) REFERENCES `{$fk['foreign_table_name']}` (`{$fk['foreign_column_name']}`) - ON DELETE {$fk['delete_rule']} - ON UPDATE {$fk['update_rule']} SQL; + // Add ON DELETE rule if specified + if (!empty($fk['delete_rule'])) { + $constraint .= " ON DELETE " . strtoupper($fk['delete_rule']); + } + + // Add ON UPDATE rule if specified + if (!empty($fk['update_rule'])) { + $constraint .= " ON UPDATE " . strtoupper($fk['update_rule']); + } + try { $mariadb->exec($constraint); logMessage("Added foreign key constraint {$fk['constraint_name']} to $tableName", 'INFO'); } catch (PDOException $e) { - logMessage("Error creating table `$tableName`: " . $e->getMessage(), 'ERROR'); + if (strpos($e->getMessage(), 'foreign key constraint') !== false) { + logMessage("Foreign key constraint issue for `$tableName`: " . $e->getMessage(), 'WARNING'); + } else { + logMessage("Error creating table `$tableName`: " . $e->getMessage(), 'ERROR'); + } } } }