Skip to content

Commit

Permalink
add notValid option for postgres foreign keys (#26775)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaewun authored and taylorotwell committed Dec 7, 2018
1 parent 28cdb6b commit 3086582
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public function compileForeign(Blueprint $blueprint, Fluent $command)
$sql .= $command->initiallyImmediate ? ' initially immediate' : ' initially deferred';
}

if (! is_null($command->notValid)) {
$sql .= ' not valid';
}

return $sql;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Database/DatabasePostgresSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,13 @@ public function testCompileForeign()

$this->assertCount(1, $statements);
$this->assertEquals('alter table "users" add constraint "users_parent_id_foreign" foreign key ("parent_id") references "parents" ("id") on delete cascade deferrable initially deferred', $statements[0]);

$blueprint = new Blueprint('users');
$blueprint->foreign('parent_id')->references('id')->on('parents')->onDelete('cascade')->deferrable()->notValid();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table "users" add constraint "users_parent_id_foreign" foreign key ("parent_id") references "parents" ("id") on delete cascade deferrable not valid', $statements[0]);
}

public function testAddingGeometry()
Expand Down

0 comments on commit 3086582

Please sign in to comment.