public constraintSql ( Cake\Database\Schema\Table $table, $name ) | ||
$table | Cake\Database\Schema\Table |
public function constraintSql(Table $table, $name)
{
$data = $table->constraint($name);
$out = 'CONSTRAINT ' . $this->_driver->quoteIdentifier($name);
if ($data['type'] === Table::CONSTRAINT_PRIMARY) {
$out = 'PRIMARY KEY';
}
if ($data['type'] === Table::CONSTRAINT_UNIQUE) {
$out .= ' UNIQUE';
}
return $this->_keySql($out, $data);
}
/** * Test the constraintSql method. * * @dataProvider constraintSqlProvider */ public function testConstraintSql($name, $data, $expected) { $driver = $this->_getMockedDriver(); $schema = new PostgresSchema($driver); $table = (new Table('schema_articles'))->addColumn('title', ['type' => 'string', 'length' => 255])->addColumn('author_id', ['type' => 'integer'])->addConstraint($name, $data); $this->assertTextEquals($expected, $schema->constraintSql($table, $name)); }