Skip to content

Loading…

DBAL-63: Custom Types always detected as changed when orm:schema-tool:update #1846

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user xphere81:

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:

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;
    }
}
/****
 * @entity
 */
namespace Project;
class Entity
{
    /****
     * @id
     * @column(type="integer")
     */
    private $id;

    /****
     * @column(type="custom")
     */
    private $custom;
}
$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),
));

{noformat:title=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

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Issue was closed with resolution "Duplicate"

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.