Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for DROP IF EXISTS clause #115

Merged
merged 5 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\.$#'
Expand Down
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