From 7c8d4a98a7c2fb9d28d6de998c636c4423880452 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Tue, 20 Jun 2023 15:50:09 +0900 Subject: [PATCH 1/5] feat: add support for DROP IF EXISTS clause --- src/Schema/Grammar.php | 2 +- tests/Schema/BlueprintTest.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index 57f8a5af..5da84605 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -327,7 +327,7 @@ public function compileDrop(Blueprint $blueprint, Fluent $command) */ public function compileDropIfExists(Blueprint $blueprint, Fluent $command) { - return $this->compileDrop($blueprint, $command); + return 'drop table if exists '.$this->wrapTable($blueprint); } /** diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index 4b617752..ba2e4aa4 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -62,7 +62,7 @@ public function testCreateTable(): void ); } - public function testDropTable(): void + public function test_dropTable(): void { $conn = $this->getDefaultConnection(); @@ -77,6 +77,23 @@ public function testDropTable(): void ); } + public function test_dropTableIfExists(): void + { + $conn = $this->getDefaultConnection(); + + $blueprint = new Blueprint('Test3', function (Blueprint $table) { + $table->dropIfExists(); + }); + + $queries = $blueprint->toSql($conn, new Grammar()); + $this->assertEquals( + 'drop table if exists `Test3`', + $queries[0] + ); + + self::assertTrue($conn->statement($queries[0])); + } + public function testAddColumn(): void { $conn = $this->getDefaultConnection(); From 68950ce65f12c3975c59f1d3de42519ae82cea06 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Tue, 20 Jun 2023 15:57:41 +0900 Subject: [PATCH 2/5] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 760e98d9..993d8be9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Added - Added deprecation warnings to `Connection::runDdl` and `Connection::runDdls` (#98) - Added `ManagesMutations::insertOrUpdateUsingMutation` and `UsesMutations::insertOrUpdateUsingMutation` to do upserts (#109) +- Added Support for `Schema\Builder::dropIfExists()` (#115) Changed - `Connection::waitForOperation` and `Connection::isDoneOperation` has been removed. (#99) From f51771c087e4670ac3aeecdbf39c3b9d07c86b72 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Tue, 20 Jun 2023 15:59:00 +0900 Subject: [PATCH 3/5] f --- tests/Schema/BlueprintTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index ba2e4aa4..2e31d93c 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -77,7 +77,7 @@ public function test_dropTable(): void ); } - public function test_dropTableIfExists(): void + public function test_dropIfExists(): void { $conn = $this->getDefaultConnection(); From cdddd8ba23520cd8f3baa3aeca38c43d27b24e29 Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Tue, 20 Jun 2023 17:17:48 +0900 Subject: [PATCH 4/5] Update tests/Schema/BlueprintTest.php Co-authored-by: Tomohito YABU --- tests/Schema/BlueprintTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index 2e31d93c..1d486cc4 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -91,7 +91,7 @@ public function test_dropIfExists(): void $queries[0] ); - self::assertTrue($conn->statement($queries[0])); + $this->assertTrue($conn->statement($queries[0])); } public function testAddColumn(): void From c1fec4f9bbedf5675c4c949e484f6e9fbc3d0d68 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Fri, 7 Jul 2023 18:08:29 +0900 Subject: [PATCH 5/5] fix test --- phpstan.neon | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 4bea3d95..25bf19cb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -25,8 +25,6 @@ parameters: path: src/Connection.php - message: '#^Cannot cast mixed to int\.$#' path: src/Eloquent/Model.php - - message: '#^Method Colopl\\Spanner\\Schema\\Builder::createBlueprint\(\) should return Illuminate\\Database\\Schema\\Blueprint but returns mixed\.$#' - path: src/Schema/Builder.php - message: '#^Property Illuminate\\Database\\Schema\\Builder::\$resolver \(Closure\) in isset\(\) is not nullable\.$#' path: src/Schema/Builder.php - message: '#^Using nullsafe method call on non-nullable type Illuminate\\Database\\DatabaseTransactionsManager\. Use -> instead\.$#'