Migrations\Shell\Task\MigrationDiffTask::getConstraints PHP Метод

getConstraints() защищенный Метод

This will look for contraints addition, contraints removal and changes in contraints metadata such as change of referenced columns if the old constraints and the new one have the same name. The method directly sets the diff in a property of the class.
protected getConstraints ( ) : void
Результат void
    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;
                }
            }
        }
    }