Skip to content

Commit

Permalink
Fix typo in foreign key SQL.
Browse files Browse the repository at this point in the history
Also cause truncations to cascade in postgres. Not cascading truncation
causes postgres to error out when trying to clean up fixture data.
  • Loading branch information
markstory committed Sep 6, 2014
1 parent 653147e commit c29bed8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Database/Schema/PostgresSchema.php
Expand Up @@ -428,7 +428,7 @@ protected function _keySql($prefix, $data) {
);
if ($data['type'] === Table::CONSTRAINT_FOREIGN) {
return $prefix . sprintf(
' FOREIGN KEY (%s) REFERENCES %s (%s) ON UPDATE %s ON DELETE %s DEFERABLE INITIALLY IMMEDIATE',
' FOREIGN KEY (%s) REFERENCES %s (%s) ON UPDATE %s ON DELETE %s DEFERRABLE INITIALLY IMMEDIATE',
implode(', ', $columns),
$this->_driver->quoteIdentifier($data['references'][0]),
$this->_driver->quoteIdentifier($data['references'][1]),
Expand Down Expand Up @@ -471,7 +471,7 @@ public function createTableSql(Table $table, $columns, $constraints, $indexes) {
public function truncateTableSql(Table $table) {
$name = $this->_driver->quoteIdentifier($table->name());
return [
sprintf('TRUNCATE %s RESTART IDENTITY', $name)
sprintf('TRUNCATE %s RESTART IDENTITY CASCADE', $name)
];
}

Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Database/Schema/PostgresSchemaTest.php
Expand Up @@ -680,31 +680,31 @@ public static function constraintSqlProvider() {
'author_id_idx',
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id']],
'CONSTRAINT "author_id_idx" FOREIGN KEY ("author_id") ' .
'REFERENCES "authors" ("id") ON UPDATE RESTRICT ON DELETE RESTRICT DEFERABLE INITIALLY IMMEDIATE'
'REFERENCES "authors" ("id") ON UPDATE RESTRICT ON DELETE RESTRICT DEFERRABLE INITIALLY IMMEDIATE'
],
[
'author_id_idx',
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'cascade'],
'CONSTRAINT "author_id_idx" FOREIGN KEY ("author_id") ' .
'REFERENCES "authors" ("id") ON UPDATE CASCADE ON DELETE RESTRICT DEFERABLE INITIALLY IMMEDIATE'
'REFERENCES "authors" ("id") ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY IMMEDIATE'
],
[
'author_id_idx',
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'restrict'],
'CONSTRAINT "author_id_idx" FOREIGN KEY ("author_id") ' .
'REFERENCES "authors" ("id") ON UPDATE RESTRICT ON DELETE RESTRICT DEFERABLE INITIALLY IMMEDIATE'
'REFERENCES "authors" ("id") ON UPDATE RESTRICT ON DELETE RESTRICT DEFERRABLE INITIALLY IMMEDIATE'
],
[
'author_id_idx',
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'setNull'],
'CONSTRAINT "author_id_idx" FOREIGN KEY ("author_id") ' .
'REFERENCES "authors" ("id") ON UPDATE SET NULL ON DELETE RESTRICT DEFERABLE INITIALLY IMMEDIATE'
'REFERENCES "authors" ("id") ON UPDATE SET NULL ON DELETE RESTRICT DEFERRABLE INITIALLY IMMEDIATE'
],
[
'author_id_idx',
['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'noAction'],
'CONSTRAINT "author_id_idx" FOREIGN KEY ("author_id") ' .
'REFERENCES "authors" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT DEFERABLE INITIALLY IMMEDIATE'
'REFERENCES "authors" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT DEFERRABLE INITIALLY IMMEDIATE'
],
];
}
Expand Down

0 comments on commit c29bed8

Please sign in to comment.