[DBAL-232] Custom commented column type removal causes unknown column type exception Created: 06/Mar/12  Updated: 21/Nov/13  Resolved: 21/Nov/13

Status: Resolved
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: 2.2.1
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: Aigars Gedroics Assignee: Benjamin Eberlei
Resolution: Won't Fix Votes: 0
Labels: None


 Description   

Problem happens when initially, as example, there was commented type "foo" registered and used:

Doctrine\DBAL\Types\Type::addType('foo', 'FooType');
$em->getConnection()
    ->getDatabasePlatform()
    ->markDoctrineTypeCommented(Doctrine\DBAL\Types\Type::getType('foo'));

When the type usage and declaration is removed, the database schema upgrade fails.
This is because DBAL reads the comment from the database and tries to find the type 'foo'.

I suggest ignoring the database column comment and stick to the standard type recognition in case the type is not declared.



 Comments   
Comment by Aigars Gedroics [ 09/Mar/12 ]

Trivial solution would be:

--- a/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+++ b/Doctrine/DBAL/Schema/AbstractSchemaManager.php
@@ -878,7 +878,9 @@ abstract class AbstractSchemaManager
     public function extractDoctrineTypeFromComment($comment, $currentType)
     {
         if (preg_match("(\(DC2Type:([a-zA-Z0-9]+)\))", $comment, $match)) {
-            $currentType = $match[1];
+                       if (Types\Type::hasType($match[1])) {
+                               $currentType = $match[1];
+                       }
         }
         return $currentType;
     }
Comment by Steve Müller [ 07/Nov/13 ]

Proposed solution applied in PR:

https://github.com/doctrine/dbal/pull/406

Comment by Doctrine Bot [ 09/Nov/13 ]

A related Github Pull-Request [GH-406] was closed:
https://github.com/doctrine/dbal/pull/406

Comment by Steve Müller [ 09/Nov/13 ]

As discussed with ocramius, it is not a good solution to silence this error during schema introspection. The problem has to be fixed by registering the missing types in the application or modifying the database schema manually by removing the column comment. This is what the current exception message suggest anyways.

Generated at Sat Apr 19 17:03:54 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.