Skip to content

Commit

Permalink
Add the methods added to the schema dialect to the BaseSchema abstrac…
Browse files Browse the repository at this point in the history
…t class
  • Loading branch information
HavokInspiration committed Oct 15, 2015
1 parent fe17df5 commit a34ac48
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/Database/Schema/BaseSchema.php
Expand Up @@ -230,6 +230,22 @@ abstract public function createTableSql(Table $table, $columns, $constraints, $i
*/
abstract public function columnSql(Table $table, $name);

/**
* Generate the SQL queries needed to add foreign key constraints to the table
*
* @param \Cake\Database\Schema\Table $table The table instance the foreign key constraints are.
* @return array SQL fragment.
*/
abstract public function addConstraintSql(Table $table);

/**
* Generate the SQL queries needed to drop foreign key constraints from the table
*
* @param \Cake\Database\Schema\Table $table The table instance the foreign key constraints are.
* @return array SQL fragment.
*/
abstract public function dropConstraintSql(Table $table);

/**
* Generate the SQL fragments for defining table constraints.
*
Expand Down
6 changes: 6 additions & 0 deletions src/Database/Schema/MysqlSchema.php
Expand Up @@ -389,6 +389,9 @@ public function constraintSql(Table $table, $name)
return $this->_keySql($out, $data);
}

/**
* {@inheritDoc}
*/
public function addConstraintSql(Table $table)
{
$sqlPattern = 'ALTER TABLE %s ADD %s';
Expand All @@ -404,6 +407,9 @@ public function addConstraintSql(Table $table)
return $sql;
}

/**
* {@inheritDoc}
*/
public function dropConstraintSql(Table $table)
{
$sqlPattern = 'ALTER TABLE %s DROP FOREIGN KEY %s';
Expand Down
7 changes: 6 additions & 1 deletion src/Database/Schema/PostgresSchema.php
Expand Up @@ -417,7 +417,9 @@ public function columnSql(Table $table, $name)
return $out;
}


/**
* {@inheritDoc}
*/
public function addConstraintSql(Table $table)
{
$sqlPattern = 'ALTER TABLE %s ADD %s';
Expand All @@ -433,6 +435,9 @@ public function addConstraintSql(Table $table)
return $sql;
}

/**
* {@inheritDoc}
*/
public function dropConstraintSql(Table $table)
{
$sqlPattern = 'ALTER TABLE %s DROP CONSTRAINT %s';
Expand Down
6 changes: 6 additions & 0 deletions src/Database/Schema/SqlserverSchema.php
Expand Up @@ -365,6 +365,9 @@ public function columnSql(Table $table, $name)
return $out;
}

/**
* {@inheritDoc}
*/
public function addConstraintSql(Table $table)
{
$sqlPattern = 'ALTER TABLE %s ADD %s';
Expand All @@ -380,6 +383,9 @@ public function addConstraintSql(Table $table)
return $sql;
}

/**
* {@inheritDoc}
*/
public function dropConstraintSql(Table $table)
{
$sqlPattern = 'ALTER TABLE %s DROP CONSTRAINT %s';
Expand Down
16 changes: 14 additions & 2 deletions src/Database/Schema/Table.php
Expand Up @@ -718,13 +718,25 @@ public function truncateSql(ConnectionInterface $connection)
return $dialect->truncateTableSql($this);
}

public function addConstraintSql(Connection $connection)
/**
* Generate the SQL statements to add the constraints to the table
*
* @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
* @return array SQL to drop a table.
*/
public function addConstraintSql(ConnectionInterface $connection)
{
$dialect = $connection->driver()->schemaDialect();
return $dialect->addConstraintSql($this);
}

public function dropConstraintSql(Connection $connection)
/**
* Generate the SQL statements to drop the constraints to the table
*
* @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
* @return array SQL to drop a table.
*/
public function dropConstraintSql(ConnectionInterface $connection)
{
$dialect = $connection->driver()->schemaDialect();
return $dialect->dropConstraintSql($this);
Expand Down

0 comments on commit a34ac48

Please sign in to comment.