Skip to content

Commit

Permalink
fix MSSQL DBAL exception conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jul 11, 2022
1 parent 11544da commit bff9f14
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Schema/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
use Atk4\Data\Persistence;
use Atk4\Data\Persistence\Sql\Connection;
use Atk4\Data\Reference\HasOne;
use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Table;

Expand Down Expand Up @@ -107,8 +109,19 @@ public function create(): self

public function drop(): self
{
$this->createSchemaManager()
->dropTable($this->getDatabasePlatform()->quoteIdentifier($this->table->getName()));
try {
$this->createSchemaManager()
->dropTable($this->getDatabasePlatform()->quoteIdentifier($this->table->getName()));
} catch (DatabaseObjectNotFoundException $e) {
// fix exception not converted to TableNotFoundException for MSSQL
// https://github.com/doctrine/dbal/pull/5492
if ($this->getDatabasePlatform() instanceof SQLServerPlatform && $e->getPrevious()->getCode() === 3701
&& preg_match('~[cC]annot drop the table \'.*\', because it does not exist or you do not have permission\.~', $e->getMessage())) {
throw new TableNotFoundException($e->getPrevious(), $e->getQuery());
}

throw $e;
}

$this->createdTableNames = array_diff($this->createdTableNames, [$this->table->getName()]);

Expand Down

0 comments on commit bff9f14

Please sign in to comment.