protected function prepareForeignConstraint(DOMElement $table, DOMXPath $xpath, Table $schemaTable)
    {
        $foreignKeys = $xpath->query(sprintf('/database/table[@name="%s"]/foreign', $table->getAttribute('name')));

        /** @var DOMElement $foreignKey */
        foreach ($foreignKeys as $foreignKey) {
            $foreignTable = $foreignKey->getAttribute('foreignTable');
            $references = $foreignKey->getElementsByTagName('reference');

            /** @var DOMElement $reference */
            foreach ($references as $reference) {
                $localColumn = $reference->getAttribute('local');
                $foreignColumn = $reference->getAttribute('foreign');
                $constraintName = sprintf(
                    '%s_%s_%s_%s_foreign',
                    $table->getAttribute('name'),
                    $foreignTable,
                    $localColumn,
                    $foreignColumn
                );

                $schemaTable->addConstraint(
                    $constraintName,
                    [
                        'type' => 'foreign',
                        'columns' => [$localColumn],
                        'references' => [$foreignTable, $foreignColumn],
                        'update' => $foreignKey->getAttribute('onUpdate'),
                        'delete' => $foreignKey->getAttribute('onDelete')
                    ]
                );
            }
        }
    }