protected function getConstraints()
{
foreach ($this->commonTables as $table => $currentSchema) {
$currentConstraints = $currentSchema->constraints();
$oldConstraints = $this->dumpSchema[$table]->constraints();
// brand new constraints
$addedConstraints = array_diff($currentConstraints, $oldConstraints);
foreach ($addedConstraints as $constraintName) {
$this->templateData[$table]['constraints']['add'][$constraintName] = $currentSchema->constraint($constraintName);
}
// constraints having the same name between new and old schema
// if present in both, check if they are the same : if not, remove the old one and add the new one
foreach ($currentConstraints as $constraintName) {
$constraint = $currentSchema->constraint($constraintName);
if (in_array($constraintName, $oldConstraints) && $constraint !== $this->dumpSchema[$table]->constraint($constraintName)) {
$this->templateData[$table]['constraints']['remove'][$constraintName] = $this->dumpSchema[$table]->constraint($constraintName);
$this->templateData[$table]['constraints']['add'][$constraintName] = $constraint;
}
}
// removed constraints
$removedConstraints = array_diff($oldConstraints, $currentConstraints);
foreach ($removedConstraints as $constraintName) {
$constraint = $this->dumpSchema[$table]->constraint($constraintName);
if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) {
$this->templateData[$table]['constraints']['remove'][$constraintName] = $constraint;
} else {
$this->templateData[$table]['indexes']['remove'][$constraintName] = $constraint;
}
}
}
}