Skip to content

Commit

Permalink
Merge branch '4.3.x' into 5.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Nov 29, 2024
2 parents b08207e + b299d3b commit efe2095
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.2.0"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.3.0"
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ jobs:
- name: "Install IBM DB2 CLI driver"
working-directory: /tmp
run: |
wget https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz
wget https://github.com/ibmdb/db2drivers/raw/refs/heads/main/clidriver/v11.5.9/linuxx64_odbc_cli.tar.gz
tar xf linuxx64_odbc_cli.tar.gz
rm linuxx64_odbc_cli.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ on:
jobs:
documentation:
name: "Documentation"
uses: "doctrine/.github/.github/workflows/documentation.yml@5.2.0"
uses: "doctrine/.github/.github/workflows/documentation.yml@5.3.0"
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ all drivers and middleware.

# Upgrade to 4.3

## Deprecated configuration-related `Table` methods

The `Table::setSchemaConfig()` method and `$_schemaConfig` property have been deprecated. Pass a `TableConfiguration`
instance to the constructor instead.

The `Table::_getMaxIdentifierLength()` method has been deprecated.

## Deprecated `AbstractAsset::_setName()`

Setting object name via `AbstractAsset::_setName()` has been deprecated. Pass the name to the `AbstractAsset`
Expand Down
16 changes: 16 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,24 @@

<!-- TODO for PHPUnit 11 -->
<referencedMethod name="PHPUnit\Framework\TestCase::iniSet"/>

<!--
https://github.com/doctrine/dbal/pull/6635
TODO: remove in 5.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\Table::_getMaxIdentifierLength" />
<referencedMethod name="Doctrine\DBAL\Schema\Table::setSchemaConfig" />
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
<errorLevel type="suppress">
<!--
https://github.com/doctrine/dbal/pull/6635
TODO: remove in 5.0.0
-->
<referencedProperty name="Doctrine\DBAL\Schema\Table::$_schemaConfig" />
</errorLevel>
</DeprecatedProperty>
<DocblockTypeContradiction>
<errorLevel type="suppress">
<!--
Expand Down
4 changes: 4 additions & 0 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public function listTables(): array
$filter = $this->connection->getConfiguration()->getSchemaAssetsFilter();
$tables = [];

$configuration = $this->createSchemaConfig()
->toTableConfiguration();

foreach ($tableColumnsByTable as $tableName => $tableColumns) {
if (! $filter($tableName)) {
continue;
Expand All @@ -214,6 +217,7 @@ public function listTables(): array
[],
$this->_getPortableTableForeignKeysList($foreignKeyColumnsByTable[$tableName] ?? []),
$tableOptionsByTable[$tableName] ?? [],
$configuration,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function __construct(
}

foreach ($tables as $table) {
$table->setSchemaConfig($this->_schemaConfig);
$this->_addTable($table);
}

Expand All @@ -109,7 +110,6 @@ protected function _addTable(Table $table): void
}

$this->_tables[$tableName] = $table;
$table->setSchemaConfig($this->_schemaConfig);
}

protected function _addSequence(Sequence $sequence): void
Expand Down Expand Up @@ -270,7 +270,7 @@ public function createNamespace(string $name): self
*/
public function createTable(string $name): Table
{
$table = new Table($name);
$table = new Table($name, [], [], [], [], [], $this->_schemaConfig->toTableConfiguration());
$this->_addTable($table);

foreach ($this->_schemaConfig->getDefaultTableOptions() as $option => $value) {
Expand Down
5 changes: 5 additions & 0 deletions src/Schema/SchemaConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ public function setDefaultTableOptions(array $defaultTableOptions): void
{
$this->defaultTableOptions = $defaultTableOptions;
}

public function toTableConfiguration(): TableConfiguration
{
return new TableConfiguration($this->maxIdentifierLength);
}
}
30 changes: 27 additions & 3 deletions src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ class Table extends AbstractAsset
'create_options' => [],
];

/** @deprecated Pass a {@link TableConfiguration} instance to the constructor instead. */
protected ?SchemaConfig $_schemaConfig = null;

private int $maxIdentifierLength;

/**
* @param array<Column> $columns
* @param array<Index> $indexes
Expand All @@ -77,13 +80,18 @@ public function __construct(
array $uniqueConstraints = [],
array $fkConstraints = [],
array $options = [],
?TableConfiguration $configuration = null,
) {
if ($name === '') {
throw InvalidTableName::new($name);
}

parent::__construct($name);

$configuration ??= (new SchemaConfig())->toTableConfiguration();

$this->maxIdentifierLength = $configuration->getMaxIdentifierLength();

foreach ($columns as $column) {
$this->_addColumn($column);
}
Expand All @@ -103,9 +111,19 @@ public function __construct(
$this->_options = array_merge($this->_options, $options);
}

/** @deprecated Pass a {@link TableConfiguration} instance to the constructor instead. */
public function setSchemaConfig(SchemaConfig $schemaConfig): void
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6635',
'%s is deprecated. Pass TableConfiguration to the constructor instead.',
__METHOD__,
);

$this->_schemaConfig = $schemaConfig;

$this->maxIdentifierLength = $schemaConfig->getMaxIdentifierLength();
}

/**
Expand Down Expand Up @@ -623,11 +641,17 @@ public function __clone()
}
}

/** @deprecated */
protected function _getMaxIdentifierLength(): int
{
return $this->_schemaConfig instanceof SchemaConfig
? $this->_schemaConfig->getMaxIdentifierLength()
: 63;
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6635',
'%s is deprecated.',
__METHOD__,
);

return $this->maxIdentifierLength;
}

protected function _addColumn(Column $column): void
Expand Down
24 changes: 24 additions & 0 deletions src/Schema/TableConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Schema;

/**
* Contains platform-specific parameters used for creating and managing objects scoped to a {@see Table}.
*/
class TableConfiguration
{
/** @internal The configuration can be only instantiated by a {@see SchemaConfig}. */
public function __construct(private readonly int $maxIdentifierLength)
{
}

/**
* Returns the maximum length of identifiers to be generated for the objects scoped to the table.
*/
public function getMaxIdentifierLength(): int
{
return $this->maxIdentifierLength;
}
}
12 changes: 10 additions & 2 deletions tests/Functional/Schema/OracleSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,16 @@ public function testListTableColumnsSameTableNamesInDifferentSchemas(): void

public function testListTableIndexesPrimaryKeyConstraintNameDiffersFromIndexName(): void
{
$table = new Table('list_table_indexes_pk_id_test');
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table = new Table(
'list_table_indexes_pk_id_test',
[],
[],
[],
[],
[],
$this->schemaManager->createSchemaConfig()->toTableConfiguration(),
);

$table->addColumn('id', Types::INTEGER, ['notnull' => true]);
$table->addUniqueIndex(['id'], 'id_unique_index');
$this->dropAndCreateTable($table);
Expand Down
66 changes: 54 additions & 12 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,15 @@ public function testAutoincrementDetection(): void
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
}

$table = new Table('test_autoincrement');
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table = new Table(
'test_autoincrement',
[],
[],
[],
[],
[],
$this->schemaManager->createSchemaConfig()->toTableConfiguration(),
);
$table->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
$table->setPrimaryKey(['id']);

Expand All @@ -716,8 +723,15 @@ public function testAutoincrementDetectionMulticolumns(): void
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
}

$table = new Table('test_not_autoincrement');
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table = new Table(
'test_not_autoincrement',
[],
[],
[],
[],
[],
$this->schemaManager->createSchemaConfig()->toTableConfiguration(),
);
$table->addColumn('id', Types::INTEGER);
$table->addColumn('other_id', Types::INTEGER);
$table->setPrimaryKey(['id', 'other_id']);
Expand All @@ -735,8 +749,15 @@ public function testUpdateSchemaWithForeignKeyRenaming(): void
$table->addColumn('id', Types::INTEGER);
$table->setPrimaryKey(['id']);

$tableFK = new Table('test_fk_rename');
$tableFK->setSchemaConfig($this->schemaManager->createSchemaConfig());
$tableFK = new Table(
'test_fk_rename',
[],
[],
[],
[],
[],
$this->schemaManager->createSchemaConfig()->toTableConfiguration(),
);
$tableFK->addColumn('id', Types::INTEGER);
$tableFK->addColumn('fk_id', Types::INTEGER);
$tableFK->setPrimaryKey(['id']);
Expand All @@ -749,8 +770,15 @@ public function testUpdateSchemaWithForeignKeyRenaming(): void
$this->schemaManager->createTable($table);
$this->schemaManager->createTable($tableFK);

$tableFKNew = new Table('test_fk_rename');
$tableFKNew->setSchemaConfig($this->schemaManager->createSchemaConfig());
$tableFKNew = new Table(
'test_fk_rename',
[],
[],
[],
[],
[],
$this->schemaManager->createSchemaConfig()->toTableConfiguration(),
);
$tableFKNew->addColumn('id', Types::INTEGER);
$tableFKNew->addColumn('rename_fk_id', Types::INTEGER);
$tableFKNew->setPrimaryKey(['id']);
Expand Down Expand Up @@ -894,8 +922,15 @@ protected function createTestTable(string $name = 'test_table', array $data = []
/** @param mixed[] $options */
protected function getTestTable(string $name, array $options = []): Table
{
$table = new Table($name, [], [], [], [], $options);
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table = new Table(
$name,
[],
[],
[],
[],
$options,
$this->schemaManager->createSchemaConfig()->toTableConfiguration(),
);
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);
$table->setPrimaryKey(['id']);
$table->addColumn('test', Types::STRING, ['length' => 255]);
Expand All @@ -906,8 +941,15 @@ protected function getTestTable(string $name, array $options = []): Table

protected function getTestCompositeTable(string $name): Table
{
$table = new Table($name, [], [], [], [], []);
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table = new Table(
$name,
[],
[],
[],
[],
[],
$this->schemaManager->createSchemaConfig()->toTableConfiguration(),
);
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('other_id', Types::INTEGER, ['notnull' => true]);
$table->setPrimaryKey(['id', 'other_id']);
Expand Down
10 changes: 6 additions & 4 deletions tests/Schema/AbstractComparatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public function testCompareMissingTable(): void
{
$schemaConfig = new SchemaConfig();

$table = new Table('bugdb', ['integercolumn1' => new Column('integercolumn1', Type::getType(Types::INTEGER))]);
$table->setSchemaConfig($schemaConfig);
$table = new Table('bugdb', [
'integercolumn1' => new Column('integercolumn1', Type::getType(Types::INTEGER)),
], [], [], [], [], $schemaConfig->toTableConfiguration());

$schema1 = new Schema([$table], [], $schemaConfig);
$schema2 = new Schema([], [], $schemaConfig);
Expand All @@ -109,8 +110,9 @@ public function testCompareNewTable(): void
{
$schemaConfig = new SchemaConfig();

$table = new Table('bugdb', ['integercolumn1' => new Column('integercolumn1', Type::getType(Types::INTEGER))]);
$table->setSchemaConfig($schemaConfig);
$table = new Table('bugdb', [
'integercolumn1' => new Column('integercolumn1', Type::getType(Types::INTEGER)),
], [], [], [], [], $schemaConfig->toTableConfiguration());

$schema1 = new Schema([], [], $schemaConfig);
$schema2 = new Schema([$table], [], $schemaConfig);
Expand Down

0 comments on commit efe2095

Please sign in to comment.