Timestamp vs DateTime DIFF (mySQL) #734

Open
thedave80 opened this Issue Aug 1, 2013 · 1 comment

2 participants

@thedave80

When using propel-gen diff to create a DB changesets, propel will behave strange in some circumstances.

First try: Creating a default timestamp field in schema:

Propel diff creates a DATETIME field now:

ALTER TABLE changelog CHANGE complete_dt complete_dt DATETIME NOT NULL;

-- But I wanted to created a timestamp field :-/

Second try, using sqlType to enforce TIMESTAMP:

ALTER TABLE changelog CHANGE complete_dt complete_dt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- This works! Applying patch with propel-gen up

Now I want to apply some auto-update which works much smoother with mySQL5.6:

ALTER TABLE changelog CHANGE complete_dt complete_dt TIMESTAMP NOT NULL DEFAULT \'CURRENT_TIMESTAMP\';

-- Didn't work. defaultValue overrides defaultExpr.

Next try:

ALTER TABLE changelog CHANGE complete_dt complete_dt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

-- Diff worked again. Lets apply patch and diff again, so see if i missed something:

ALTER TABLE changelog CHANGE complete_dt complete_dt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

-- Diff is there again. But nothing changed!

So propel can't handle combinations with timestamp and defaultExpr very well. This is one of the reasons: MysqlPlatform::initialize:47

$this->setSchemaDomainMapping(new Domain(PropelTypes::TIMESTAMP, "DATETIME"));

Native mySQL Field TIMESTAMP will be internally overwritten with DATETIME. Then, when comparing in PropelColumnComparator::compareColumns, the check will fail, since TIMESTAMP != DATETIME. Also the check will fail since I did use defaultExpr instead of defaultValue.

I think I saw some other issues in this area, but can't find the link right now.

@pedrocasado

any workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment