[DBAL-63] Custom Types always detected as changed when orm:schema-tool:update Created: 16/Nov/10  Updated: 16/Nov/10  Resolved: 16/Nov/10

Status: Resolved
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: 2.0.0-BETA4
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Berny Cantos Assignee: Benjamin Eberlei
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Ubuntu 10.10, MySQL 5.1.49, PHP 5.3.3



 Description   

I defined a custom type for DBAL and used it in an entity annotation. Every time I call doctrine orm:schema-tool:update, even when no changes are been made to the code, DBAL thinks the schema has changed and needs an update. The type declaration is done in cli-config.php, when creating the EntityManager.

See the code and output below:

Project/CustomType.php
namespace Project;

use \Doctrine\DBAL\Platforms\AbstractPlatform,
    \Doctrine\DBAL\Types\Type;

class CustomType extends Type
{
    const TYPE = 'custom';

    public function getSqlDeclaration(array $fieldDeclaration,
                                      AbstractPlatform $platform)
    {
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
    }

    public function getName()
    {
        return self::TYPE;
    }
}
Project/Entity.php
/**
 * @entity
 */
namespace Project;
class Entity
{
    /**
     * @id
     * @column(type="integer")
     */
    private $id;

    /**
     * @column(type="custom")
     */
    private $custom;
}
cli-config.php
$cache = new \Doctrine\Common\Cache\ApcCache;
$config = new \Doctrine\ORM\Configuration;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);

$driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/Project');
$config->setMetadataDriverImpl($driverImpl);

$config->setProxyDir(APPLICATION_PATH . '/Proxies');
$config->setProxyNamespace('Proxies');
$config->setAutoGenerateProxyClasses(true);

$connectionOptions = array(
    'driver'   => 'pdo_mysql',
    'dbname'   => 'project',
    'user'     => '#user#',
    'password' => '#password#',
    'host'     => 'localhost',
);

\Doctrine\DBAL\Types\Type::addType('custom', 'Project\CustomType');
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em),
));
Console Output
#:~ doctrine orm:schema-tool:create --dump-sql
CREATE TABLE Entity (id INT NOT NULL, custom VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB

#:~ doctrine orm:schema-tool:create
Creating database schema...
Database schema created successfully!

#:~ doctrine orm:schema-tool:update --dump-sql
ALTER TABLE Entity CHANGE custom custom VARCHAR(255) NOT NULL

#:~ doctrine orm:schema-tool:update --force
Updating database schema...
Database schema updated successfully!

#:~ doctrine orm:schema-tool:update --dump-sql
ALTER TABLE Entity CHANGE custom custom VARCHAR(255) NOT NULL


 Comments   
Comment by Benjamin Eberlei [ 16/Nov/10 ]

Yes, it thinks its a varchar and wants to update that definition. This is a duplicate of DBAL-42

Generated at Sun Apr 20 16:16:21 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.