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

Add $ifExists and $cascade to dropTable() methods #319

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
- Enh #315: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov)
- New #314: Implement `ColumnFactory` class (@Tigrov)
- Enh #317: Separate column type constants (@Tigrov)
- New #318: Realize `ColumnBuilder` class (@Tigrov)
- Enh #318: Realize `ColumnBuilder` class (@Tigrov)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Enh #318: Realize `ColumnBuilder` class (@Tigrov)
- New #318: Realize `ColumnBuilder` class (@Tigrov)

- Enh #319: Set more specific result type in `Connection::createCommand()` method (@vjik)
- Enh #320: Update according changes in `ColumnSchemaInterface` (@Tigrov)
- New #322: Add `ColumnDefinitionBuilder` class (@Tigrov)
- Enh #323: Refactor `Dsn` class (@Tigrov)
Expand Down
9 changes: 9 additions & 0 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\NotSupportedException;

use function array_pop;
use function count;
Expand All @@ -21,6 +22,14 @@
*/
final class Command extends AbstractPdoCommand
{
public function dropTable(string $table, bool $ifExists = false, bool $cascade = false): static
{
if ($cascade) {
throw new NotSupportedException('SQLite doesn\'t support cascade drop table.');
}
return parent::dropTable($table, $ifExists);
}

public function insertWithReturningPks(string $table, array $columns): bool|array
{
$params = [];
Expand Down
3 changes: 1 addition & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Yiisoft\Db\Sqlite;

use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Quoter;
use Yiisoft\Db\Schema\QuoterInterface;
Expand Down Expand Up @@ -34,7 +33,7 @@ public function __clone()
}
}

public function createCommand(string $sql = null, array $params = []): PdoCommandInterface
public function createCommand(string $sql = null, array $params = []): Command
{
$command = new Command($this);

Expand Down
13 changes: 9 additions & 4 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,15 @@ public function testDropPrimaryKey(): void
$command->dropPrimaryKey('{{table}}', '{{name}}');
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testDropTableCascade(): void
{
$command = $this->getConnection()->createCommand();

$this->expectException(NotSupportedException::class);
$this->expectExceptionMessage('SQLite doesn\'t support cascade drop table.');
$command->dropTable('{{table}}', cascade: true);
}

public function testDropUnique(): void
{
$db = $this->getConnection();
Expand Down
9 changes: 1 addition & 8 deletions tests/Support/TestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Yiisoft\Db\Sqlite\Tests\Support;

use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Sqlite\Connection;
use Yiisoft\Db\Sqlite\Driver;
use Yiisoft\Db\Sqlite\Dsn;
Expand All @@ -16,11 +13,7 @@ trait TestTrait
{
private string $dsn = '';

/**
* @throws Exception
* @throws InvalidConfigException
*/
protected function getConnection(bool $fixture = false): PdoConnectionInterface
protected function getConnection(bool $fixture = false): Connection
{
$db = new Connection(new Driver($this->getDsn()), DbHelper::getSchemaCache());

Expand Down
Loading