I have managed to get working a solution for the timestamp datatype for MySQL. I don't yet know how to create patches etc. so I put describe here my work and I hope that if you are looking for a way to make this work you can use my work to help you, or even better, if you are able to make this fix get into core, all the better.
In your database schema use as shown in the example below:
$schema['vchess_moves'] = array(
'description' => 'Contains the list of moves for each game',
'fields' => array(
'timestamp' => array(
'description' => 'Exact date and time of the move',
'type' => 'timestamp',
'not null' => TRUE,
In the MySQL version of schema.inc in /includes/database/mysql/schema.inc file add code for the timestamp datatype in the getFieldTypeMap() function:
public function getFieldTypeMap() {
// Put :normal last so it gets preserved by array_flip. This makes
// it much easier for modules (such as schema.module) to map
// database types back into schema types.
// $map does not use drupal_static as its value never changes.
static $map = array(
'varchar:normal' => 'VARCHAR',
'char:normal' => 'CHAR',
'text:tiny' => 'TINYTEXT',
'text:small' => 'TINYTEXT',
'text:medium' => 'MEDIUMTEXT',
'text:big' => 'LONGTEXT',
'text:normal' => 'TEXT',
'serial:tiny' => 'TINYINT',
'serial:small' => 'SMALLINT',
'serial:medium' => 'MEDIUMINT',
'serial:big' => 'BIGINT',
'serial:normal' => 'INT',
'int:tiny' => 'TINYINT',
'int:small' => 'SMALLINT',
'int:medium' => 'MEDIUMINT',
'int:big' => 'BIGINT',
'int:normal' => 'INT',
'float:tiny' => 'FLOAT',
'float:small' => 'FLOAT',
'float:medium' => 'FLOAT',
'float:big' => 'DOUBLE',
'float:normal' => 'FLOAT',
'numeric:normal' => 'DECIMAL',
'timestamp:normal'=> 'TIMESTAMP', // This is a line you need to add for timestamp
'enum:normal' => 'ENUM', // See drupal.org/node/1464354 if you want ENUM as well
'blob:big' => 'LONGBLOB',
'blob:normal' => 'BLOB',
);
return $map;
}
That's it!
I've tested it on Drupal 7.10, and for me it works great. As I said, if someone can help get this into core, that would be brilliant. I understand that a similar thing should also be added for the other database schema files, but I don't see that this should stop this MySQL fix going in already.
You might also like to read:
- http://drupal.org/node/1464354 ENUM datatype
- http://drupal.org/node/293483 Add support for more field types to schema API
Comments
Comment #1
Eric_A CreditAttribution: Eric_A commentedSome more reading: #866340: Remove support for date and time types
Comment #2
ziobudda CreditAttribution: ziobudda commentedWhy is this not in the core ? 2 years old...
Comment #3
drupalshrek CreditAttribution: drupalshrek commentedI think from the Eric_A links, it is a conscious decision to not do so.
Comment #5
kenorb CreditAttribution: kenorb commentedComment #6
daffie CreditAttribution: daffie commentedThis belongs with Drupal 7. The related issue is also Drupal 7.