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) 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\.$#' 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..1d486cc4 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_dropIfExists(): 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] + ); + + $this->assertTrue($conn->statement($queries[0])); + } + public function testAddColumn(): void { $conn = $this->getDefaultConnection();