Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
PixoVoid committed Dec 3, 2024
1 parent 6683d2b commit 3979af0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
}
Expand Down

0 comments on commit 3979af0

Please sign in to comment.