diff --git a/CHANGELOG.md b/CHANGELOG.md index 89226aa0..e8a303d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index 26ef69e7..1ebc90e1 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -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!'); } /** diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index ece0b619..a8078319 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -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();