From 0eb249e66941d0a192ed04acf7225e5642e5cf7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 11 Dec 2021 11:32:14 +0100 Subject: [PATCH] Drop type comments entirely This feature is only useful for reverse-engineering purposes since we have platform-aware comparison. Reverse-engineering is not enough to justify having that feature, and ORM metadata reverse-engineered from the database can still be adjusted afterwards. --- UPGRADE.md | 5 + docs/en/explanation/dc2type-comments.rst | 39 ----- docs/en/sidebar.rst | 1 - src/Platforms/AbstractPlatform.php | 18 +-- src/Schema/AbstractSchemaManager.php | 18 --- src/Schema/DB2SchemaManager.php | 3 +- src/Schema/MySQLSchemaManager.php | 3 +- src/Schema/OracleSchemaManager.php | 3 +- src/Schema/PostgreSQLSchemaManager.php | 3 +- src/Schema/SQLServerSchemaManager.php | 3 +- src/Schema/SqliteSchemaManager.php | 6 - .../Schema/MySQLSchemaManagerTest.php | 12 -- .../SchemaManagerFunctionalTestCase.php | 27 ---- .../AbstractMySQLPlatformTestCase.php | 5 +- tests/Platforms/AbstractPlatformTestCase.php | 10 -- tests/Platforms/DB2PlatformTest.php | 5 +- tests/Platforms/OraclePlatformTest.php | 5 +- tests/Platforms/PostgreSQLPlatformTest.php | 33 +---- tests/Platforms/SQLServerPlatformTestCase.php | 23 +-- tests/Schema/ComparatorTest.php | 9 -- tests/Schema/SqliteSchemaManagerTest.php | 139 ------------------ 21 files changed, 20 insertions(+), 350 deletions(-) delete mode 100644 docs/en/explanation/dc2type-comments.rst diff --git a/UPGRADE.md b/UPGRADE.md index e621483d151..208dd6b39f6 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,11 @@ awareness about deprecated code. # Upgrade to 4.0 +## BC BREAK: Types can no longer be reverse-engineered reliably + +Introspecting a table no longer guarantees getting the same column types that +were used when creating that table. + ## BC BREAK: Removed `AbstractPlatform::prefersIdentityColumns()` The `AbstractPlatform::prefersIdentityColumns()` method has been removed. diff --git a/docs/en/explanation/dc2type-comments.rst b/docs/en/explanation/dc2type-comments.rst deleted file mode 100644 index 8a669a0449c..00000000000 --- a/docs/en/explanation/dc2type-comments.rst +++ /dev/null @@ -1,39 +0,0 @@ -Doctrine SQL comments -===================== - -In some occasions DBAL generates ``DC2Type`` SQL comments in columns of -the databases schemas that is maintained by Doctrine. These comments -have a functional purpose in DBAL. - -``DC2`` is a shorthand for Doctrine 2, as opposed to `Doctrine 1 -`_, -an ancestor that relied on `the active record pattern -`_. - -These comments are here to help with reverse engineering. Inside the -DBAL, the schema manager can leverage them to resolve ambiguities when -it comes to determining the correct DBAL type for a given column. - -For instance: You are following a `Database First approach -`_, -and want to use GUIDs in your application while using a platform that does not have a native type for -this mapping. -By commenting columns that hold GUIDs with ``(DC2Type:guid)``, you can -let the DBAL know it is supposed to use ``Doctrine\DBAL\Types\GuidType`` -when dealing with that column. -When using reverse engineering tools, this can be used to generate -accurate information. -For instance, if you use Doctrine ORM, there is `a reverse engineering example -`_ -to show how to generate a proper mapping. - -A table with such a column may have a declaration that looks as follows: - -.. code-block:: sql - - CREATE TABLE "movies" ( - uuid CHAR(36) NOT NULL, --(DC2Type:guid) - title varchar(255) NOT NULL - …, - PRIMARY KEY(uuid) - ) diff --git a/docs/en/sidebar.rst b/docs/en/sidebar.rst index 377b235d0e3..91b6cb2ae85 100644 --- a/docs/en/sidebar.rst +++ b/docs/en/sidebar.rst @@ -20,5 +20,4 @@ reference/upgrading reference/testing - explanation/dc2type-comments.rst explanation/implicit-indexes diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 9b6d07a819f..ad0b784e0a6 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -375,26 +375,12 @@ public function hasDoctrineTypeMappingFor(string $dbType): bool return isset($this->doctrineTypeMapping[$dbType]); } - /** - * Gets the comment to append to a column comment that helps parsing this type in reverse engineering. - */ - public function getDoctrineTypeComment(Type $doctrineType): string - { - return '(DC2Type:' . $doctrineType->getName() . ')'; - } - /** * Gets the comment of a passed column modified by potential doctrine type comment hints. */ protected function getColumnComment(Column $column): string { - $comment = $column->getComment(); - - if ($column->getType()->requiresSQLCommentHint($this)) { - $comment .= $this->getDoctrineTypeComment($column->getType()); - } - - return $comment; + return $column->getComment(); } /** @@ -2510,7 +2496,7 @@ private function columnToArray(Column $column): array return array_merge($column->toArray(), [ 'name' => $column->getQuotedName($this), 'version' => $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : false, - 'comment' => $this->getColumnComment($column), + 'comment' => $column->getComment(), ]); } diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index 9d190f77e51..894e5607d17 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -20,7 +20,6 @@ use function array_values; use function assert; use function count; -use function preg_match; use function strtolower; /** @@ -845,23 +844,6 @@ public function createSchemaConfig(): SchemaConfig return $schemaConfig; } - /** - * Given a table comment this method tries to extract a type hint for Doctrine Type. If the type hint is found, - * it's removed from the comment. - * - * @return string|null The extracted Doctrine type or NULL of the type hint was not found. - */ - final protected function extractDoctrineTypeFromComment(?string &$comment): ?string - { - if ($comment === null || preg_match('/(.*)\(DC2Type:(((?!\)).)+)\)(.*)/', $comment, $match) === 0) { - return null; - } - - $comment = $match[1] . $match[4]; - - return $match[2]; - } - /** * @throws DatabaseRequired */ diff --git a/src/Schema/DB2SchemaManager.php b/src/Schema/DB2SchemaManager.php index d4c2980f570..a90e02d5383 100644 --- a/src/Schema/DB2SchemaManager.php +++ b/src/Schema/DB2SchemaManager.php @@ -61,8 +61,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column } } - $type = $this->extractDoctrineTypeFromComment($tableColumn['comment']) - ?? $this->_platform->getDoctrineTypeMapping($tableColumn['typename']); + $type = $this->_platform->getDoctrineTypeMapping($tableColumn['typename']); switch (strtolower($tableColumn['typename'])) { case 'varchar': diff --git a/src/Schema/MySQLSchemaManager.php b/src/Schema/MySQLSchemaManager.php index cb8c0398a56..78b50bf5565 100644 --- a/src/Schema/MySQLSchemaManager.php +++ b/src/Schema/MySQLSchemaManager.php @@ -127,8 +127,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column $scale = 0; $precision = null; - $type = $this->extractDoctrineTypeFromComment($tableColumn['comment']) - ?? $this->_platform->getDoctrineTypeMapping($dbType); + $type = $this->_platform->getDoctrineTypeMapping($dbType); switch ($dbType) { case 'char': diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index f86b0f4cbb4..0122a07fc26 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -139,8 +139,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column $scale = (int) $tableColumn['data_scale']; } - $type = $this->extractDoctrineTypeFromComment($tableColumn['comments']) - ?? $this->_platform->getDoctrineTypeMapping($dbType); + $type = $this->_platform->getDoctrineTypeMapping($dbType); switch ($dbType) { case 'number': diff --git a/src/Schema/PostgreSQLSchemaManager.php b/src/Schema/PostgreSQLSchemaManager.php index dd62dc248ae..2fec6d2dca2 100644 --- a/src/Schema/PostgreSQLSchemaManager.php +++ b/src/Schema/PostgreSQLSchemaManager.php @@ -321,8 +321,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column $tableColumn['complete_type'] = $tableColumn['domain_complete_type']; } - $type = $this->extractDoctrineTypeFromComment($tableColumn['comment']) - ?? $this->_platform->getDoctrineTypeMapping($dbType); + $type = $this->_platform->getDoctrineTypeMapping($dbType); switch ($dbType) { case 'smallint': diff --git a/src/Schema/SQLServerSchemaManager.php b/src/Schema/SQLServerSchemaManager.php index 0cc29fe1a40..95ff4df758a 100644 --- a/src/Schema/SQLServerSchemaManager.php +++ b/src/Schema/SQLServerSchemaManager.php @@ -108,8 +108,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column $fixed = true; } - $type = $this->extractDoctrineTypeFromComment($tableColumn['comment']) - ?? $this->_platform->getDoctrineTypeMapping($dbType); + $type = $this->_platform->getDoctrineTypeMapping($dbType); $options = [ 'fixed' => $fixed, diff --git a/src/Schema/SqliteSchemaManager.php b/src/Schema/SqliteSchemaManager.php index 05da61a369c..5a9abafe1d5 100644 --- a/src/Schema/SqliteSchemaManager.php +++ b/src/Schema/SqliteSchemaManager.php @@ -260,12 +260,6 @@ protected function _getPortableTableColumnList(string $table, string $database, $comment = $this->parseColumnCommentFromSQL($columnName, $createSql); - $type = $this->extractDoctrineTypeFromComment($comment); - - if ($type !== null) { - $column->setType(Type::getType($type)); - } - $column->setComment($comment); } diff --git a/tests/Functional/Schema/MySQLSchemaManagerTest.php b/tests/Functional/Schema/MySQLSchemaManagerTest.php index da700f24dbd..8f048254917 100644 --- a/tests/Functional/Schema/MySQLSchemaManagerTest.php +++ b/tests/Functional/Schema/MySQLSchemaManagerTest.php @@ -17,7 +17,6 @@ use Doctrine\DBAL\Tests\TestUtil; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; -use Doctrine\DBAL\Types\Types; class MySQLSchemaManagerTest extends SchemaManagerFunctionalTestCase { @@ -391,17 +390,6 @@ public function testListFloatTypeColumns(): void self::assertTrue($columns['col_unsigned']->getUnsigned()); } - public function testJsonColumnType(): void - { - $table = new Table('test_mysql_json'); - $table->addColumn('col_json', 'json'); - $this->dropAndCreateTable($table); - - $columns = $this->schemaManager->listTableColumns('test_mysql_json'); - - self::assertSame(Types::JSON, $columns['col_json']->getType()->getName()); - } - public function testColumnDefaultCurrentTimestamp(): void { $platform = $this->schemaManager->getDatabasePlatform(); diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index d58cf9d0b3b..453d8d84602 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -33,7 +33,6 @@ use Doctrine\DBAL\Types\TextType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; -use ReflectionMethod; use function array_filter; use function array_keys; @@ -1128,32 +1127,6 @@ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNo self::assertNull($tableDiff); } - /** - * @dataProvider commentsProvider - */ - public function testExtractDoctrineTypeFromComment(string $comment, ?string $expectedType): void - { - $re = new ReflectionMethod($this->schemaManager, 'extractDoctrineTypeFromComment'); - $re->setAccessible(true); - - self::assertSame($expectedType, $re->invokeArgs($this->schemaManager, [&$comment])); - } - - /** - * @return mixed[][] - */ - public static function commentsProvider(): iterable - { - return [ - 'invalid custom type comments' => ['should.return.null', null], - 'valid doctrine type' => ['(DC2Type:guid)', 'guid'], - 'valid with dots' => ['(DC2Type:type.should.return)', 'type.should.return'], - 'valid with namespace' => ['(DC2Type:Namespace\Class)', 'Namespace\Class'], - 'valid with extra closing bracket' => ['(DC2Type:should.stop)).before)', 'should.stop'], - 'valid with extra opening brackets' => ['(DC2Type:should((.stop)).before)', 'should((.stop'], - ]; - } - public function testCreateAndListSequences(): void { if (! $this->schemaManager->getDatabasePlatform()->supportsSequences()) { diff --git a/tests/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Platforms/AbstractMySQLPlatformTestCase.php index 69e422ed99e..d76a76f741d 100644 --- a/tests/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Platforms/AbstractMySQLPlatformTestCase.php @@ -223,10 +223,7 @@ public function getAlterTableColumnCommentsSQL(): array */ public function getCreateTableColumnTypeCommentsSQL(): array { - return [ - "CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', " - . 'PRIMARY KEY(id))', - ]; + return ['CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL, PRIMARY KEY(id))']; } public function testChangeIndexWithForeignKeys(): void diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index 02558a11b5a..ea2052da0d2 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -448,16 +448,6 @@ public function testAlterTableColumnComments(): void self::assertEquals($this->getAlterTableColumnCommentsSQL(), $this->platform->getAlterTableSQL($tableDiff)); } - public function testCreateTableColumnTypeComments(): void - { - $table = new Table('test'); - $table->addColumn('id', 'integer'); - $table->addColumn('data', 'array'); - $table->setPrimaryKey(['id']); - - self::assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->platform->getCreateTableSQL($table)); - } - /** * @return string[] */ diff --git a/tests/Platforms/DB2PlatformTest.php b/tests/Platforms/DB2PlatformTest.php index 8a0b16a160b..7dab7612d1b 100644 --- a/tests/Platforms/DB2PlatformTest.php +++ b/tests/Platforms/DB2PlatformTest.php @@ -164,10 +164,7 @@ public function getAlterTableColumnCommentsSQL(): array */ public function getCreateTableColumnTypeCommentsSQL(): array { - return [ - 'CREATE TABLE test (id INTEGER NOT NULL, "data" CLOB(1M) NOT NULL, PRIMARY KEY(id))', - 'COMMENT ON COLUMN test."data" IS \'(DC2Type:array)\'', - ]; + return ['CREATE TABLE test (id INTEGER NOT NULL, "data" CLOB(1M) NOT NULL, PRIMARY KEY(id))']; } public function testGeneratesCreateTableSQLWithCommonIndexes(): void diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 6228db6114c..c589fd204f5 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -288,10 +288,7 @@ public function getCreateTableColumnCommentsSQL(): array */ public function getCreateTableColumnTypeCommentsSQL(): array { - return [ - 'CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))', - "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", - ]; + return ['CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))']; } /** diff --git a/tests/Platforms/PostgreSQLPlatformTest.php b/tests/Platforms/PostgreSQLPlatformTest.php index 9820291bc1f..8a26672b18b 100644 --- a/tests/Platforms/PostgreSQLPlatformTest.php +++ b/tests/Platforms/PostgreSQLPlatformTest.php @@ -370,10 +370,7 @@ public function getAlterTableColumnCommentsSQL(): array */ public function getCreateTableColumnTypeCommentsSQL(): array { - return [ - 'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))', - "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", - ]; + return ['CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))']; } /** @@ -646,8 +643,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // BINARY -> VARBINARY // BLOB -> VARBINARY $diff = $comparator->diffTable($table1, $table2); - self::assertNotNull($diff); - self::assertEmpty($this->platform->getAlterTableSQL($diff)); + self::assertNull($diff); $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'binary', ['length' => 42]); @@ -658,8 +654,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // BINARY -> BLOB // BLOB -> BINARY $diff = $comparator->diffTable($table1, $table2); - self::assertNotNull($diff); - self::assertEmpty($this->platform->getAlterTableSQL($diff)); + self::assertNull($diff); $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'blob'); @@ -670,8 +665,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // BINARY -> BINARY with changed length // BLOB -> BLOB $diff = $comparator->diffTable($table1, $table2); - self::assertNotNull($diff); - self::assertEmpty($this->platform->getAlterTableSQL($diff)); + self::assertNull($diff); } /** @@ -830,25 +824,6 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers(): v ); } - public function testAltersTableColumnCommentIfRequiredByType(): void - { - $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime'))]); - $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime_immutable'))]); - - $tableDiff = $this->createComparator() - ->diffTable($table1, $table2); - - self::assertNotNull($tableDiff); - self::assertSame( - [ - 'ALTER TABLE "foo" ALTER "bar" TYPE TIMESTAMP(0) WITHOUT TIME ZONE', - 'ALTER TABLE "foo" ALTER "bar" DROP DEFAULT', - 'COMMENT ON COLUMN "foo"."bar" IS \'(DC2Type:datetime_immutable)\'', - ], - $this->platform->getAlterTableSQL($tableDiff) - ); - } - protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(): string { return 'CONSTRAINT "select" UNIQUE (foo)'; diff --git a/tests/Platforms/SQLServerPlatformTestCase.php b/tests/Platforms/SQLServerPlatformTestCase.php index 91a9dda69a9..0fd0937e2ce 100644 --- a/tests/Platforms/SQLServerPlatformTestCase.php +++ b/tests/Platforms/SQLServerPlatformTestCase.php @@ -759,11 +759,7 @@ public function getAlterTableColumnCommentsSQL(): array */ public function getCreateTableColumnTypeCommentsSQL(): array { - return [ - 'CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))', - "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:array)', " - . "N'SCHEMA', 'dbo', N'TABLE', 'test', N'COLUMN', data", - ]; + return ['CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))']; } public function testGeneratesCreateTableSQLWithColumnComments(): void @@ -809,11 +805,6 @@ public function testGeneratesCreateTableSQLWithColumnComments(): void "EXEC sp_addextendedproperty N'MS_Description', " . "N'Doctrine 0wnz comments for reserved keyword columns!', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [create]", - "EXEC sp_addextendedproperty N'MS_Description', " - . "N'(DC2Type:object)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type", - "EXEC sp_addextendedproperty N'MS_Description', " - . "N'Doctrine array type.(DC2Type:array)', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type_with_comment", "EXEC sp_addextendedproperty N'MS_Description', N'O''Reilly', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", ], @@ -977,30 +968,18 @@ public function testGeneratesAlterTableSQLWithColumnComments(): void . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [added_comment_quoted]", "EXEC sp_addextendedproperty N'MS_Description', N'666', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [select]", - "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_commented_type", - "EXEC sp_addextendedproperty N'MS_Description', N'666(DC2Type:array)', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_commented_type_with_comment", "EXEC sp_addextendedproperty N'MS_Description', N'''''', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment_with_string_literal_char", // Changed columns. "EXEC sp_addextendedproperty N'MS_Description', N'primary', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', id", - "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_empty_string", "EXEC sp_dropextendedproperty N'MS_Description', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_string_0", "EXEC sp_dropextendedproperty N'MS_Description', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment", - "EXEC sp_updateextendedproperty N'MS_Description', N'Doctrine array.(DC2Type:array)', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [comment_quoted]", - "EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:object)', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [create]", "EXEC sp_updateextendedproperty N'MS_Description', N'foo', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type", - "EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:array)', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type_with_comment", "EXEC sp_updateextendedproperty N'MS_Description', N'''', " . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", ], diff --git a/tests/Schema/ComparatorTest.php b/tests/Schema/ComparatorTest.php index 3373581d70f..ff683ec1d07 100644 --- a/tests/Schema/ComparatorTest.php +++ b/tests/Schema/ComparatorTest.php @@ -16,7 +16,6 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; -use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\TestCase; use function array_keys; @@ -1219,14 +1218,6 @@ public static function getCompareColumnComments(): iterable ]; } - public function testCompareCommentedTypes(): void - { - $column1 = new Column('foo', Type::getType(Types::ARRAY)); - $column2 = new Column('foo', Type::getType(Types::OBJECT)); - - self::assertFalse($this->comparator->columnsEqual($column1, $column2)); - } - public function testForeignKeyRemovalWithRenamedLocalColumn(): void { $fromSchema = new Schema([ diff --git a/tests/Schema/SqliteSchemaManagerTest.php b/tests/Schema/SqliteSchemaManagerTest.php index 57b4816c62e..c87d6826402 100644 --- a/tests/Schema/SqliteSchemaManagerTest.php +++ b/tests/Schema/SqliteSchemaManagerTest.php @@ -153,67 +153,6 @@ public static function getDataColumnComment(): iterable 'a', 'CREATE TABLE "a" ("a" TEXT DEFAULT "a" COLLATE RTRIM)', ], - 'Single column with type comment' => [ - '(DC2Type:x)', - 'a', - 'CREATE TABLE "a" ("a" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) -)', - ], - 'Multiple similar columns with type comment 1' => [ - '', - 'b', - 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" TEXT DEFAULT "a" COLLATE RTRIM, ' - . '"bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) -)', - ], - 'Multiple similar columns with type comment 2' => [ - '(DC2Type:x)', - 'b', - 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" TEXT DEFAULT "a" COLLATE RTRIM, ' - . '"b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) -)', - ], - 'Multiple similar columns on different lines, with type comment 1' => [ - '', - 'bb', - 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) -, "bb" TEXT DEFAULT "a" COLLATE RTRIM', - ], - 'Multiple similar columns on different lines, with type comment 2' => [ - '(DC2Type:x)', - 'bb', - 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) -, "b" TEXT DEFAULT "a" COLLATE RTRIM', - ], - 'Column with numeric but no comment 1' => [ - '', - 'a', - 'CREATE TABLE "a" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) -, "c" CHAR(36) NOT NULL --(DC2Type:guid) -)', - ], - 'Column with numeric but no comment 2' => [ - '', - 'a', - 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) -, "c" CHAR(36) NOT NULL --(DC2Type:guid) -)', - ], - 'Column with numeric but no comment 3' => [ - '(DC2Type:guid)', - 'c', - 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) -, "c" CHAR(36) NOT NULL --(DC2Type:guid) -)', - ], - 'Column with numeric but no comment 4' => [ - '(DC2Type:array)', - 'b', - 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, - "b" CLOB NOT NULL, --(DC2Type:array) - "c" CHAR(36) NOT NULL --(DC2Type:guid) - )', - ], 'Column "bar", select "bar" with no comment' => [ '', 'bar', @@ -225,40 +164,6 @@ public static function getDataColumnComment(): iterable PRIMARY KEY(id) )', ], - 'Column "bar", select "bar" with type comment' => [ - '(DC2Type:x)', - 'bar', - 'CREATE TABLE dummy_table ( - id INTEGER NOT NULL, - foo VARCHAR(255) COLLATE "utf-8" NOT NULL, - "bar" VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:x) - baz VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:y) - PRIMARY KEY(id) - )', - ], - 'Column "bar", select "baz" with no comment' => [ - '', - 'baz', - 'CREATE TABLE dummy_table ( - id INTEGER NOT NULL, - foo VARCHAR(255) COLLATE "utf-8" NOT NULL, - "bar" INTEGER NOT NULL, - baz VARCHAR(255) COLLATE "utf-8" NOT NULL, - PRIMARY KEY(id) - )', - ], - 'Column "bar", select "baz" with type comment' => [ - '(DC2Type:y)', - 'baz', - 'CREATE TABLE dummy_table ( - id INTEGER NOT NULL, - foo VARCHAR(255) COLLATE "utf-8" NOT NULL, - "bar" INTEGER NOT NULL, --(DC2Type:x) - baz VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:y) - PRIMARY KEY(id) - )', - ], - 'Column "bar#", select "bar#" with no comment' => [ '', 'bar#', @@ -270,17 +175,6 @@ public static function getDataColumnComment(): iterable PRIMARY KEY(id) )', ], - 'Column "bar#", select "bar#" with type comment' => [ - '(DC2Type:x)', - 'bar#', - 'CREATE TABLE dummy_table ( - id INTEGER NOT NULL, - foo VARCHAR(255) COLLATE "utf-8" NOT NULL, - "bar#" VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:x) - baz VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:y) - PRIMARY KEY(id) - )', - ], 'Column "bar#", select "baz" with no comment' => [ '', 'baz', @@ -292,17 +186,6 @@ public static function getDataColumnComment(): iterable PRIMARY KEY(id) )', ], - 'Column "bar#", select "baz" with type comment' => [ - '(DC2Type:y)', - 'baz', - 'CREATE TABLE dummy_table ( - id INTEGER NOT NULL, - foo VARCHAR(255) COLLATE "utf-8" NOT NULL, - "bar#" INTEGER NOT NULL, --(DC2Type:x) - baz VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:y) - PRIMARY KEY(id) - )', - ], 'Column "bar/", select "bar/" with no comment' => [ '', @@ -315,17 +198,6 @@ public static function getDataColumnComment(): iterable PRIMARY KEY(id) )', ], - 'Column "bar/", select "bar/" with type comment' => [ - '(DC2Type:x)', - 'bar/', - 'CREATE TABLE dummy_table ( - id INTEGER NOT NULL, - foo VARCHAR(255) COLLATE "utf-8" NOT NULL, - "bar/" VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:x) - baz VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:y) - PRIMARY KEY(id) - )', - ], 'Column "bar/", select "baz" with no comment' => [ '', 'baz', @@ -337,17 +209,6 @@ public static function getDataColumnComment(): iterable PRIMARY KEY(id) )', ], - 'Column "bar/", select "baz" with type comment' => [ - '(DC2Type:y)', - 'baz', - 'CREATE TABLE dummy_table ( - id INTEGER NOT NULL, - foo VARCHAR(255) COLLATE "utf-8" NOT NULL, - "bar/" INTEGER COLLATE "utf-8" NOT NULL, --(DC2Type:x) - baz VARCHAR(255) COLLATE "utf-8" NOT NULL, --(DC2Type:y) - PRIMARY KEY(id) - )', - ], ]; } }