Skip to content

Commit

Permalink
Merge branch '3.4.x' into 4.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Feb 17, 2022
2 parents 09625b6 + 5f0233f commit d267561
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 157 deletions.
10 changes: 5 additions & 5 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ The following methods have been removed.

# Upgrade to 3.4

# Deprecated `AbstractPlatform` schema introspection methods
## Deprecated `AbstractPlatform` schema introspection methods

The following schema introspection methods have been deprecated:

Expand All @@ -649,22 +649,22 @@ The following schema introspection methods have been deprecated:

The queries used for schema introspection are an internal implementation detail of the DBAL.

# Deprecated `collate` option for MySQL
## Deprecated `collate` option for MySQL

This undocumented option is deprecated in favor of `collation`.

# Deprecated `AbstractPlatform::getListTableConstraintsSQL()`
## Deprecated `AbstractPlatform::getListTableConstraintsSQL()`

This method is unused by the DBAL since 2.0.

# Deprecated `Type::getName()`
## Deprecated `Type::getName()`

This will method is not useful for the DBAL anymore, and will be removed in 4.0.
As a consequence, depending on the name of a type being `json` for `jsonb` to
be used for the Postgres platform is deprecated in favor of extending
`Doctrine\DBAL\Types\JsonType`.

# Deprecated `AbstractPlatform::getColumnComment()` and `AbstractPlatform::getDoctrineTypeComment()`
## Deprecated `AbstractPlatform::getColumnComment()` and `AbstractPlatform::getDoctrineTypeComment()`

DBAL no longer needs column comments to ensure proper diffing. Note that both
methods should probably have been marked as internal as these comments were an
Expand Down
97 changes: 72 additions & 25 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ public function listTableColumns(string $table, ?string $database = null): array
return $this->_getPortableTableColumnList($table, $database, $tableColumns);
}

/**
* @return Column[]
*
* @throws Exception
*/
protected function doListTableColumns(string $table, ?string $database = null): array
{
$database = $this->ensureDatabase(
$database ?? $this->_conn->getDatabase(),
__METHOD__
);

return $this->_getPortableTableColumnList(
$table,
$database,
$this->selectDatabaseColumns($database, $this->normalizeName($table))
->fetchAllAssociative()
);
}

/**
* Lists the indexes for a given table returning an array of Index instances.
*
Expand All @@ -157,6 +177,27 @@ public function listTableIndexes(string $table): array
return $this->_getPortableTableIndexesList($tableIndexes, $table);
}

/**
* @return Index[]
*
* @throws Exception
*/
protected function doListTableIndexes(string $table): array
{
$database = $this->ensureDatabase(
$this->_conn->getDatabase(),
__METHOD__
);

return $this->_getPortableTableIndexesList(
$this->selectDatabaseIndexes(
$database,
$this->normalizeName($table)
)->fetchAllAssociative(),
$table
);
}

/**
* Returns true if all the given tables exist.
*
Expand Down Expand Up @@ -220,11 +261,10 @@ protected function filterAssetNames(array $assetNames): array
*/
public function listTables(): array
{
$currentDatabase = $this->_conn->getDatabase();

if ($currentDatabase === null) {
throw DatabaseRequired::new(__METHOD__);
}
$currentDatabase = $this->ensureDatabase(
$this->_conn->getDatabase(),
__METHOD__
);

/** @var array<string,list<array<string,mixed>>> $columns */
$columns = $this->fetchAllAssociativeGrouped(
Expand Down Expand Up @@ -266,38 +306,25 @@ public function listTables(): array
*/
public function listTableDetails(string $name): Table
{
$currentDatabase = $this->_conn->getDatabase();

if ($currentDatabase === null) {
throw DatabaseRequired::new(__METHOD__);
}
$currentDatabase = $this->ensureDatabase(
$this->_conn->getDatabase(),
__METHOD__
);

$normalizedName = $this->normalizeName($name);

$tableOptions = $this->getDatabaseTableOptions($currentDatabase, $normalizedName);

if ($this->_platform->supportsForeignKeyConstraints()) {
$foreignKeys = $this->_getPortableTableForeignKeysList(
$this->selectDatabaseForeignKeys($currentDatabase, $normalizedName)
->fetchAllAssociative()
);
$foreignKeys = $this->listTableForeignKeys($name);
} else {
$foreignKeys = [];
}

return new Table(
$name,
$this->_getPortableTableColumnList(
$name,
$currentDatabase,
$this->selectDatabaseColumns($currentDatabase, $normalizedName)
->fetchAllAssociative()
),
$this->_getPortableTableIndexesList(
$this->selectDatabaseIndexes($currentDatabase, $normalizedName)
->fetchAllAssociative(),
$name
),
$this->listTableColumns($name, $currentDatabase),
$this->listTableIndexes($name),
[],
$foreignKeys,
$tableOptions[$normalizedName] ?? []
Expand Down Expand Up @@ -387,6 +414,26 @@ public function listTableForeignKeys(string $table, ?string $database = null): a
return $this->_getPortableTableForeignKeysList($tableForeignKeys);
}

/**
* @return ForeignKeyConstraint[]
*
* @throws Exception
*/
protected function doListTableForeignKeys(string $table, ?string $database = null): array
{
$database = $this->ensureDatabase(
$database ?? $this->_conn->getDatabase(),
__METHOD__
);

return $this->_getPortableTableForeignKeysList(
$this->selectDatabaseForeignKeys(
$database,
$this->normalizeName($table)
)->fetchAllAssociative()
);
}

/* drop*() Methods */

/**
Expand Down
24 changes: 24 additions & 0 deletions src/Schema/DB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ public function listTableNames(): array
return $this->filterAssetNames($this->_getPortableTablesList($tables));
}

/**
* {@inheritDoc}
*/
public function listTableColumns(string $table, ?string $database = null): array
{
return $this->doListTableColumns($table, $database);
}

/**
* {@inheritDoc}
*/
public function listTableIndexes(string $table): array
{
return $this->doListTableIndexes($table);
}

/**
* {@inheritDoc}
*/
public function listTableForeignKeys(string $table, ?string $database = null): array
{
return $this->doListTableForeignKeys($table, $database);
}

/**
* {@inheritdoc}
*
Expand Down
24 changes: 24 additions & 0 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ class MySQLSchemaManager extends AbstractSchemaManager
"''" => "'",
];

/**
* {@inheritDoc}
*/
public function listTableColumns(string $table, ?string $database = null): array
{
return $this->doListTableColumns($table, $database);
}

/**
* {@inheritDoc}
*/
public function listTableIndexes(string $table): array
{
return $this->doListTableIndexes($table);
}

/**
* {@inheritDoc}
*/
public function listTableForeignKeys(string $table, ?string $database = null): array
{
return $this->doListTableForeignKeys($table, $database);
}

/**
* {@inheritdoc}
*/
Expand Down
24 changes: 24 additions & 0 deletions src/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@
*/
class OracleSchemaManager extends AbstractSchemaManager
{
/**
* {@inheritDoc}
*/
public function listTableColumns(string $table, ?string $database = null): array
{
return $this->doListTableColumns($table, $database);
}

/**
* {@inheritDoc}
*/
public function listTableIndexes(string $table): array
{
return $this->doListTableIndexes($table);
}

/**
* {@inheritDoc}
*/
public function listTableForeignKeys(string $table, ?string $database = null): array
{
return $this->doListTableForeignKeys($table, $database);
}

/**
* {@inheritdoc}
*/
Expand Down
24 changes: 24 additions & 0 deletions src/Schema/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ class PostgreSQLSchemaManager extends AbstractSchemaManager
{
private ?string $currentSchema = null;

/**
* {@inheritDoc}
*/
public function listTableColumns(string $table, ?string $database = null): array
{
return $this->doListTableColumns($table, $database);
}

/**
* {@inheritDoc}
*/
public function listTableIndexes(string $table): array
{
return $this->doListTableIndexes($table);
}

/**
* {@inheritDoc}
*/
public function listTableForeignKeys(string $table, ?string $database = null): array
{
return $this->doListTableForeignKeys($table, $database);
}

/**
* {@inheritDoc}
*/
Expand Down
45 changes: 24 additions & 21 deletions src/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use function preg_match;
use function sprintf;
use function str_replace;
use function str_starts_with;
use function strpos;
use function strtok;

Expand All @@ -34,6 +33,30 @@ class SQLServerSchemaManager extends AbstractSchemaManager
{
private ?string $databaseCollation = null;

/**
* {@inheritDoc}
*/
public function listTableColumns(string $table, ?string $database = null): array
{
return $this->doListTableColumns($table, $database);
}

/**
* {@inheritDoc}
*/
public function listTableIndexes(string $table): array
{
return $this->doListTableIndexes($table);
}

/**
* {@inheritDoc}
*/
public function listTableForeignKeys(string $table, ?string $database = null): array
{
return $this->doListTableForeignKeys($table, $database);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -251,26 +274,6 @@ protected function _getPortableViewDefinition(array $view): View
return new View($view['name'], $view['definition']);
}

/**
* {@inheritdoc}
*/
public function listTableIndexes(string $table): array
{
$sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());

try {
$tableIndexes = $this->_conn->fetchAllAssociative($sql);
} catch (Exception $e) {
if (str_starts_with($e->getMessage(), 'SQLSTATE [01000, 15472]')) {
return [];
}

throw $e;
}

return $this->_getPortableTableIndexesList($tableIndexes, $table);
}

public function alterTable(TableDiff $tableDiff): void
{
if (count($tableDiff->removedColumns) > 0) {
Expand Down

0 comments on commit d267561

Please sign in to comment.