Cake\Database\Schema\PostgresSchema::constraintSql PHP Method

constraintSql() public method

{@inheritDoc}
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);
    }

Usage Example

Example #1
0
 /**
  * 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));
 }