Skip to content

Commit

Permalink
fix: throw exception if no primary key is defined. (#58)
Browse files Browse the repository at this point in the history
Co-authored-by: Taka Oyama <[email protected]>
# Conflicts:
#	tests/Schema/BlueprintTest.php
  • Loading branch information
taka-oyama committed Jan 17, 2023
1 parent f14e67a commit b41c094
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Changed
Fixed
- SessionPool was not cleared if php terminated immediately after calling `CacheSessionPool::clear`.

Changed
- Checks that primary key is defined in schema and throws an exception if not defined.

# v4.3.0

Added
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected function addPrimaryKeys(Blueprint $blueprint)
if (! is_null($primary = $this->getCommandByName($blueprint, 'primary'))) {
return "primary key ({$this->columnize($primary->columns)})";
}
return '';
throw new LogicException('Cloud Spanner require a primary key!');
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/Schema/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ public function testDropIndex(): void
);
}

public function test_no_primaryKey(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Cloud Spanner require a primary key!');

$blueprint = new Blueprint('test', function (Blueprint $table) {
$table->create();
$table->uuid('id');
});
$blueprint->toSql($this->getDefaultConnection(), new Grammar());
}

public function testCompositePrimaryKey(): void
{
$conn = $this->getDefaultConnection();
Expand Down

0 comments on commit b41c094

Please sign in to comment.