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
  • Loading branch information
taka-oyama committed Feb 24, 2023
1 parent 12ab08f commit 6354185
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v5.0.0 (Not Released Yet)

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

# v4.7.0 (Not released yet)

Chore
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 6354185

Please sign in to comment.