Skip to content

Commit

Permalink
Remove support for passing assets as names
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Sep 17, 2021
1 parent 0cdabe7 commit 6f3b9c4
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 418 deletions.
17 changes: 3 additions & 14 deletions src/Event/SchemaDropTableEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,25 @@
namespace Doctrine\DBAL\Event;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Table;
use InvalidArgumentException;

/**
* Event Arguments used when the SQL query for dropping tables are generated inside {@link AbstractPlatform}.
*/
class SchemaDropTableEventArgs extends SchemaEventArgs
{
/** @var string|Table */
private $table;
private string $table;

private AbstractPlatform $platform;

private ?string $sql = null;

/**
* @param string|Table $table
*
* @throws InvalidArgumentException
*/
public function __construct($table, AbstractPlatform $platform)
public function __construct(string $table, AbstractPlatform $platform)
{
$this->table = $table;
$this->platform = $platform;
}

/**
* @return string|Table
*/
public function getTable()
public function getTable(): string
{
return $this->table;
}
Expand Down
119 changes: 18 additions & 101 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,27 +920,11 @@ public function getDropSchemaSQL(string $schemaName): string

/**
* Returns the SQL snippet to drop an existing table.
*
* @param Table|string $table
*
* @throws InvalidArgumentException
*/
public function getDropTableSQL($table): string
public function getDropTableSQL(string $table): string
{
$tableArg = $table;

if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}

if (! is_string($table)) {
throw new InvalidArgumentException(
__METHOD__ . '() expects $table parameter to be string or ' . Table::class . '.'
);
}

if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaDropTable)) {
$eventArgs = new SchemaDropTableEventArgs($tableArg, $this);
$eventArgs = new SchemaDropTableEventArgs($table, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaDropTable, $eventArgs);

if ($eventArgs->isDefaultPrevented()) {
Expand All @@ -961,76 +945,33 @@ public function getDropTableSQL($table): string

/**
* Returns the SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction.
*
* @param Table|string $table
*/
public function getDropTemporaryTableSQL($table): string
public function getDropTemporaryTableSQL(string $table): string
{
return $this->getDropTableSQL($table);
}

/**
* Returns the SQL to drop an index from a table.
*
* @param Index|string $index
* @param Table|string $table
*
* @throws InvalidArgumentException
*/
public function getDropIndexSQL($index, $table = null): string
public function getDropIndexSQL(string $name, string $table): string
{
if ($index instanceof Index) {
$index = $index->getQuotedName($this);
} elseif (! is_string($index)) {
throw new InvalidArgumentException(
__METHOD__ . '() expects $index parameter to be string or ' . Index::class . '.'
);
}

return 'DROP INDEX ' . $index;
return 'DROP INDEX ' . $name;
}

/**
* Returns the SQL to drop a constraint.
*
* @param Constraint|string $constraint
* @param Table|string $table
*/
public function getDropConstraintSQL($constraint, $table): string
public function getDropConstraintSQL(string $name, string $table): string
{
if (! $constraint instanceof Constraint) {
$constraint = new Identifier($constraint);
}

if (! $table instanceof Table) {
$table = new Identifier($table);
}

$constraint = $constraint->getQuotedName($this);
$table = $table->getQuotedName($this);

return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint;
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $name;
}

/**
* Returns the SQL to drop a foreign key.
*
* @param ForeignKeyConstraint|string $foreignKey
* @param Table|string $table
*/
public function getDropForeignKeySQL($foreignKey, $table): string
public function getDropForeignKeySQL(string $foreignKey, string $table): string
{
if (! $foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = new Identifier($foreignKey);
}

if (! $table instanceof Table) {
$table = new Identifier($table);
}

$foreignKey = $foreignKey->getQuotedName($this);
$table = $table->getQuotedName($this);

return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey;
}

Expand Down Expand Up @@ -1252,16 +1193,10 @@ public function getAlterSequenceSQL(Sequence $sequence): string
/**
* Returns the SQL to create a constraint on a table on this platform.
*
* @param Table|string $table
*
* @throws InvalidArgumentException
*/
public function getCreateConstraintSQL(Constraint $constraint, $table): string
public function getCreateConstraintSQL(Constraint $constraint, string $table): string
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}

$query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this);

$columnList = '(' . implode(', ', $constraint->getQuotedColumns($this)) . ')';
Expand Down Expand Up @@ -1294,16 +1229,10 @@ public function getCreateConstraintSQL(Constraint $constraint, $table): string
/**
* Returns the SQL to create an index on a table on this platform.
*
* @param Table|string $table The name of the table on which the index is to be created.
*
* @throws InvalidArgumentException
*/
public function getCreateIndexSQL(Index $index, $table): string
public function getCreateIndexSQL(Index $index, string $table): string
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}

$name = $index->getQuotedName($this);
$columns = $index->getColumns();

Expand Down Expand Up @@ -1343,15 +1272,9 @@ protected function getCreateIndexSQLFlags(Index $index): string

/**
* Returns the SQL to create an unnamed primary key constraint.
*
* @param Table|string $table
*/
public function getCreatePrimaryKeySQL(Index $index, $table): string
public function getCreatePrimaryKeySQL(Index $index, string $table): string
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}

return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index) . ')';
}

Expand Down Expand Up @@ -1407,14 +1330,10 @@ public function quoteSingleIdentifier(string $str): string
* Returns the SQL to create a new foreign key.
*
* @param ForeignKeyConstraint $foreignKey The foreign key constraint.
* @param Table|string $table The name of the table on which the foreign key is to be created.
* @param string $table The name of the table on which the foreign key is to be created.
*/
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table): string
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, string $table): string
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}

return 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey);
}

Expand Down Expand Up @@ -1548,20 +1467,20 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff): array
$sql = [];
if ($this->supportsForeignKeyConstraints()) {
foreach ($diff->removedForeignKeys as $foreignKey) {
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableName);
}

foreach ($diff->changedForeignKeys as $foreignKey) {
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableName);
}
}

foreach ($diff->removedIndexes as $index) {
$sql[] = $this->getDropIndexSQL($index, $tableName);
$sql[] = $this->getDropIndexSQL($index->getQuotedName($this), $tableName);
}

foreach ($diff->changedIndexes as $index) {
$sql[] = $this->getDropIndexSQL($index, $tableName);
$sql[] = $this->getDropIndexSQL($index->getQuotedName($this), $tableName);
}

return $sql;
Expand Down Expand Up @@ -2227,11 +2146,9 @@ abstract public function getDropViewSQL(string $name): string;
/**
* Returns the SQL snippet to drop an existing sequence.
*
* @param Sequence|string $sequence
*
* @throws Exception If not supported on this platform.
*/
public function getDropSequenceSQL($sequence): string
public function getDropSequenceSQL(string $name): string
{
throw NotSupported::new(__METHOD__);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff): array
} elseif ($remIndex->isUnique()) {
$sql[] = 'ALTER TABLE ' . $table . ' DROP UNIQUE ' . $remIndex->getQuotedName($this);
} else {
$sql[] = $this->getDropIndexSQL($remIndex, $table);
$sql[] = $this->getDropIndexSQL($remIndex->getQuotedName($this), $table);
}

$sql[] = $this->getCreateIndexSQL($addIndex, $table);
Expand Down
44 changes: 4 additions & 40 deletions src/Platforms/MySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\TextType;
use InvalidArgumentException;

use function array_diff_key;
use function array_merge;
Expand All @@ -25,7 +24,6 @@
use function implode;
use function in_array;
use function is_numeric;
use function is_string;
use function sprintf;
use function str_replace;
use function strcasecmp;
Expand Down Expand Up @@ -692,7 +690,7 @@ protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff): ar
continue;
}

$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableName);
}

return $sql;
Expand Down Expand Up @@ -871,35 +869,9 @@ public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey
return $query;
}

/**
* {@inheritDoc}
*/
public function getDropIndexSQL($index, $table = null): string
{
if ($index instanceof Index) {
$indexName = $index->getQuotedName($this);
} elseif (is_string($index)) {
$indexName = $index;
} else {
throw new InvalidArgumentException(
__METHOD__ . '() expects $index parameter to be string or ' . Index::class . '.'
);
}

if ($table instanceof Table) {
$table = $table->getQuotedName($this);
} elseif (! is_string($table)) {
throw new InvalidArgumentException(
__METHOD__ . '() expects $table parameter to be string or ' . Table::class . '.'
);
}

return 'DROP INDEX ' . $indexName . ' ON ' . $table;
}

protected function getDropPrimaryKeySQL(string $table): string
public function getDropIndexSQL(string $name, string $table): string
{
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
return 'DROP INDEX ' . $name . ' ON ' . $table;
}

public function getSetTransactionIsolationSQL(int $level): string
Expand Down Expand Up @@ -959,16 +931,8 @@ protected function createReservedKeywordsList(): KeywordList
* MySQL commits a transaction implicitly when DROP TABLE is executed, however not
* if DROP TEMPORARY TABLE is executed.
*/
public function getDropTemporaryTableSQL($table): string
public function getDropTemporaryTableSQL(string $table): string
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
} elseif (! is_string($table)) {
throw new InvalidArgumentException(
__METHOD__ . '() expects $table parameter to be string or ' . Table::class . '.'
);
}

return 'DROP TEMPORARY TABLE ' . $table;
}

Expand Down
30 changes: 4 additions & 26 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\BinaryType;
Expand Down Expand Up @@ -625,35 +624,14 @@ public function getListTableColumnsSQL(string $table, ?string $database = null):
);
}

/**
* {@inheritDoc}
*/
public function getDropSequenceSQL($sequence): string
public function getDropForeignKeySQL(string $foreignKey, string $table): string
{
if ($sequence instanceof Sequence) {
$sequence = $sequence->getQuotedName($this);
}

return 'DROP SEQUENCE ' . $sequence;
return $this->getDropConstraintSQL($foreignKey, $table);
}

/**
* {@inheritDoc}
*/
public function getDropForeignKeySQL($foreignKey, $table): string
public function getDropSequenceSQL(string $name): string
{
if (! $foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = new Identifier($foreignKey);
}

if (! $table instanceof Table) {
$table = new Identifier($table);
}

$foreignKey = $foreignKey->getQuotedName($this);
$table = $table->getQuotedName($this);

return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $foreignKey;
return 'DROP SEQUENCE ' . $name;
}

public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey): string
Expand Down
Loading

0 comments on commit 6f3b9c4

Please sign in to comment.