Skip to content

Remove "jsonb" and "version" options #6942

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

Merged
merged 3 commits into from
May 3, 2025
Merged
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
13 changes: 11 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ awareness about deprecated code.

# Upgrade to 5.0

## BC BREAK: Classes marked as read-only:
## BC BREAK: Removed support for the `version` column platform option

The `version` column platform option is no longer supported.

## BC BREAK: Removed support for the `jsonb` column platform option

The `jsonb` column platform option is no longer supported. `JSONB` columns on PostgreSQL are now introspected
as columns of type `JSONB`, not as columns of type `JSON` with `jsonb` option set.

## BC BREAK: Classes marked as read-only

The following classes have been marked as read-only:

Expand Down Expand Up @@ -51,7 +60,7 @@ The following classes have been marked as read-only:
- `Doctrine\DBAL\Tools\Console\ConnectionProvider\SingleConnectionProvider`
- `Doctrine\DBAL\Tools\DsnParser`

## BC BREAK: Classes marked as final:
## BC BREAK: Classes marked as final

The following classes have been marked as final:

Expand Down
19 changes: 0 additions & 19 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\Deprecation;

use function array_map;
use function array_merge;
Expand Down Expand Up @@ -129,14 +128,6 @@ public function getListViewsSQL(string $database): string
*/
public function getJsonTypeDeclarationSQL(array $column): string
{
if (! empty($column['jsonb'])) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6939',
'The "jsonb" column platform option is deprecated. Use the "JSONB" type instead.',
);
}

return 'JSON';
}

Expand Down Expand Up @@ -175,16 +166,6 @@ public function getClobTypeDeclarationSQL(array $column): string
*/
public function getDateTimeTypeDeclarationSQL(array $column): string
{
if (isset($column['version']) && $column['version'] === true) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6940',
'The "version" column platform option is deprecated.',
);

return 'TIMESTAMP';
}

return 'DATETIME';
}

Expand Down
26 changes: 3 additions & 23 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
use Doctrine\DBAL\Types\Exception\TypeNotFound;
use Doctrine\DBAL\Types\Exception\TypesException;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;

use function addcslashes;
use function array_map;
Expand Down Expand Up @@ -256,14 +255,6 @@ public function getGuidTypeDeclarationSQL(array $column): string
*/
public function getJsonTypeDeclarationSQL(array $column): string
{
if (! empty($column['jsonb'])) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6939',
'The "jsonb" column platform option is deprecated. Use the "JSONB" type instead.',
);
}

return $this->getClobTypeDeclarationSQL($column);
}

Expand Down Expand Up @@ -879,7 +870,7 @@ private function buildCreateTableSQL(Table $table, bool $createForeignKeys): arr
$columns = [];

foreach ($table->getColumns() as $column) {
$columns[] = $this->columnToArray($column);
$columns[] = $column->toArray();
}

$sql = $this->_getCreateTableSQL($tableName, $columns, $parameters);
Expand Down Expand Up @@ -2140,17 +2131,6 @@ final public function escapeStringForLike(string $inputString, string $escapeCha
return $sql;
}

/**
* @return ColumnProperties An associative array with the name of the properties of the column being declared as
* array keys.
*/
private function columnToArray(Column $column): array
{
return array_merge($column->toArray(), [
'version' => $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : false,
]);
}

/** @internal */
public function createSQLParser(): Parser
{
Expand All @@ -2167,8 +2147,8 @@ protected function getLikeWildcardCharacters(): string
*/
public function columnsEqual(Column $column1, Column $column2): bool
{
$column1Array = $this->columnToArray($column1);
$column2Array = $this->columnToArray($column2);
$column1Array = $column1->toArray();
$column2Array = $column2->toArray();

$name = UnqualifiedName::unquoted('dummy');

Expand Down
24 changes: 0 additions & 24 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
use Doctrine\DBAL\SQL\Builder\DefaultSelectSQLBuilder;
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\DateTimeType;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\Deprecation;

use function array_merge;
use function count;
Expand Down Expand Up @@ -174,16 +172,6 @@ public function getDateDiffExpression(string $date1, string $date2): string
*/
public function getDateTimeTypeDeclarationSQL(array $column): string
{
if (isset($column['version']) && $column['version'] === true) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6940',
'The "version" column platform option is deprecated.',
);

return 'TIMESTAMP(0) WITH DEFAULT';
}

return 'TIMESTAMP(0)';
}

Expand Down Expand Up @@ -498,18 +486,6 @@ protected function getDefaultValueDeclarationSQL(array $column): string
return '';
}

if (isset($column['version']) && $column['version'] === true) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6940',
'The "version" column platform option is deprecated.',
);

if ($column['type'] instanceof DateTimeType) {
$column['default'] = '1';
}
}

return parent::getDefaultValueDeclarationSQL($column);
}

Expand Down
14 changes: 1 addition & 13 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\Deprecation;
use UnexpectedValueException;

use function array_merge;
Expand Down Expand Up @@ -262,7 +261,6 @@ public function getAlterTableSQL(TableDiff $diff): array
|| $columnDiff->hasScaleChanged()
|| $columnDiff->hasFixedChanged()
|| $columnDiff->hasLengthChanged()
|| $columnDiff->hasPlatformOptionsChanged()
) {
$type = $newColumn->getType();

Expand Down Expand Up @@ -723,7 +721,7 @@ protected function initializeDoctrineTypeMappings(): void
'integer' => Types::INTEGER,
'interval' => Types::STRING,
'json' => Types::JSON,
'jsonb' => Types::JSON,
'jsonb' => Types::JSONB,
'money' => Types::DECIMAL,
'numeric' => Types::DECIMAL,
'serial' => Types::INTEGER,
Expand Down Expand Up @@ -773,16 +771,6 @@ protected function supportsColumnCollation(): bool
*/
public function getJsonTypeDeclarationSQL(array $column): string
{
if (! empty($column['jsonb'])) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6939',
'The "jsonb" column platform option is deprecated. Use the "JSONB" type instead.',
);

return 'JSONB';
}

return 'JSON';
}

Expand Down
19 changes: 0 additions & 19 deletions src/Schema/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\DBAL\Schema\Name\Parsers;
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;

use function array_merge;
use function method_exists;
Expand All @@ -33,8 +32,6 @@
* charset?: ?string,
* collation?: ?string,
* default_constraint_name?: string,
* jsonb?: bool,
* version?: bool,
* }
*/
class Column extends AbstractNamedObject
Expand Down Expand Up @@ -160,14 +157,6 @@ public function setDefault(mixed $default): self
/** @param PlatformOptions $platformOptions */
public function setPlatformOptions(array $platformOptions): self
{
if (isset($platformOptions['jsonb']) && $platformOptions['jsonb']) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6939',
'The "jsonb" column platform option is deprecated. Use the "JSONB" type instead.',
);
}

$this->_platformOptions = $platformOptions;

return $this;
Expand All @@ -176,14 +165,6 @@ public function setPlatformOptions(array $platformOptions): self
/** @param key-of<PlatformOptions> $name */
public function setPlatformOption(string $name, mixed $value): self
{
if ($name === 'jsonb' && (bool) $value === true) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6939',
'The "jsonb" column platform option is deprecated. Use the "JSONB" type instead.',
);
}

$this->_platformOptions[$name] = $value;

return $this;
Expand Down
8 changes: 0 additions & 8 deletions src/Schema/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\DBAL\Schema\ForeignKeyConstraint\ReferentialAction;
use Doctrine\DBAL\Schema\Index\IndexType;
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\Type;

use function array_change_key_case;
Expand Down Expand Up @@ -188,7 +187,6 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
$precision = null;
$scale = 0;
$fixed = false;
$jsonb = false;

$dbType = $tableColumn['typname'];
if (
Expand Down Expand Up @@ -231,8 +229,6 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column

if ($dbType === 'bpchar') {
$fixed = true;
} elseif ($dbType === 'jsonb') {
$jsonb = true;
}

$options = [
Expand All @@ -255,10 +251,6 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
$column->setPlatformOption('collation', $tableColumn['collation']);
}

if ($column->getType() instanceof JsonType) {
$column->setPlatformOption('jsonb', $jsonb);
}

return $column;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Schema/PostgreSQL/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public function testPlatformOptionsChangedColumnComparison(): void

$onlineTable = clone $table;
$table->getColumn('test')
->setPlatformOption('jsonb', true);
->setType(Type::getType(Types::JSONB));

$compareResult = $this->comparator->compareTables($onlineTable, $table);
self::assertCount(1, $compareResult->getChangedColumns());
self::assertCount(1, $compareResult->getModifiedColumns());

$changedColumn = $compareResult->getChangedColumns()['test'];

self::assertTrue($changedColumn->hasPlatformOptionsChanged());
self::assertTrue($changedColumn->hasTypeChanged());
self::assertEquals(1, $changedColumn->countChangedProperties());
}

Expand Down
7 changes: 3 additions & 4 deletions tests/Functional/Schema/PostgreSQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\DecimalType;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\JsonbType;
use Doctrine\DBAL\Types\TextType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
Expand Down Expand Up @@ -323,13 +323,12 @@ public function testPartialIndexes(): void
public function testJsonbColumn(): void
{
$table = new Table('test_jsonb');
$table->addColumn('foo', Types::JSON)->setPlatformOption('jsonb', true);
$table->addColumn('foo', Types::JSONB);
$this->dropAndCreateTable($table);

$columns = $this->schemaManager->listTableColumns('test_jsonb');

self::assertInstanceOf(JsonType::class, $columns['foo']->getType());
self::assertTrue($columns['foo']->getPlatformOption('jsonb'));
self::assertInstanceOf(JsonbType::class, $columns['foo']->getType());
}

public function testListNegativeColumnDefaultValue(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Platforms/AbstractMySQLPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ public function testModifyLimitQueryWithEmptyOffset(): void

public function testGetDateTimeTypeDeclarationSql(): void
{
self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL(['version' => false]));
self::assertEquals('TIMESTAMP', $this->platform->getDateTimeTypeDeclarationSQL(['version' => true]));
self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL([]));
}

Expand Down
7 changes: 1 addition & 6 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
Expand All @@ -40,8 +39,6 @@
/** @template T of AbstractPlatform */
abstract class AbstractPlatformTestCase extends TestCase
{
use VerifyDeprecations;

/** @var T */
protected AbstractPlatform $platform;

Expand Down Expand Up @@ -549,10 +546,8 @@ public function testReturnsJsonTypeDeclarationSQL(): void

public function testReturnsJsonbTypeDeclarationSQL(): void
{
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/6939');

self::assertSame(
$this->platform->getJsonTypeDeclarationSQL(['jsonb' => true]),
$this->platform->getJsonTypeDeclarationSQL([]),
$this->platform->getJsonbTypeDeclarationSQL([]),
);
}
Expand Down
6 changes: 0 additions & 6 deletions tests/Platforms/DB2PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,6 @@ public function testGeneratesColumnTypesDeclarationSQL(): void
self::assertEquals('SMALLINT', $this->platform->getBooleanTypeDeclarationSQL($fullColumnDef));
self::assertEquals('CLOB(1M)', $this->platform->getClobTypeDeclarationSQL($fullColumnDef));
self::assertEquals('DATE', $this->platform->getDateTypeDeclarationSQL($fullColumnDef));

self::assertEquals(
'TIMESTAMP(0) WITH DEFAULT',
$this->platform->getDateTimeTypeDeclarationSQL(['version' => true]),
);

self::assertEquals('TIMESTAMP(0)', $this->platform->getDateTimeTypeDeclarationSQL($fullColumnDef));
self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef));
}
Expand Down
Loading