diff --git a/CHANGELOG.md b/CHANGELOG.md index c2ff9c39..91489b31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,13 @@ Changed 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) - Update `export-ignore` entries in `.gitattributes` (#104) - Use abstract definitions on traits instead of relying on `@methods` `@property`. (#120) +- Stop using `call_user_func` (#121) Fixed - Transaction state was not being cleared if rolled back failed. (#107) diff --git a/src/Concerns/ManagesStaleReads.php b/src/Concerns/ManagesStaleReads.php index 08b9a8b5..ef116d68 100644 --- a/src/Concerns/ManagesStaleReads.php +++ b/src/Concerns/ManagesStaleReads.php @@ -32,9 +32,7 @@ public function cursorWithTimestampBound($query, $bindings = [], TimestampBoundI { return $this->run($query, $bindings, function ($query, $bindings) use ($timestampBound) { if ($this->pretending()) { - return call_user_func(static function() { - yield from []; - }); + return (static fn() => yield from [])(); } $options = ['parameters' => $this->prepareBindings($bindings)]; diff --git a/src/Connection.php b/src/Connection.php index b475726a..4890105a 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -276,7 +276,7 @@ public function cursor($query, $bindings = [], $useReadPdo = true): Generator { return $this->run($query, $bindings, function ($query, $bindings) { if ($this->pretending()) { - return call_user_func(function() { yield from []; }); + return (static fn() => yield from [])(); } return $this->getDatabaseContext() diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 9ff8d3eb..1c9c911d 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -108,7 +108,7 @@ public function dropIndexIfExist($table, $name) protected function createBlueprint($table, Closure $callback = null) { return isset($this->resolver) - ? call_user_func($this->resolver, $table, $callback) + ? ($this->resolver)($table, $callback) : new Blueprint($table, $callback); } } 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();