Skip to content

Commit

Permalink
Merge branch 'master' into feature/use-abstract-defs
Browse files Browse the repository at this point in the history
  • Loading branch information
taka-oyama authored Jul 19, 2023
2 parents a22e7ae + 236ed91 commit 8be1db7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/Concerns/ManagesStaleReads.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion tests/Schema/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testCreateTable(): void
);
}

public function testDropTable(): void
public function test_dropTable(): void
{
$conn = $this->getDefaultConnection();

Expand All @@ -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();
Expand Down

0 comments on commit 8be1db7

Please sign in to comment.