Skip to content
Permalink
Browse files

Fix typo in foreign key SQL.

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 c29bed81d476725a83cdb777bffa650598c32df8
Showing with 7 additions and 7 deletions.
  1. +2 −2 src/Database/Schema/PostgresSchema.php
  2. +5 −5 tests/TestCase/Database/Schema/PostgresSchemaTest.php
@@ -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]),
@@ -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)
];
}
@@ -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'
],
];
}

0 comments on commit c29bed8

Please sign in to comment.
You can’t perform that action at this time.