In my database migration file I inserted the line:
t.timestamps
Two columns, as I expected, were created: “updated_at” and “created_at”. However, their type is “datetime” and not “timestamp”.
I am using MySQL and the “timestamp” type, as I understand, is designed exactly for such cases, as it uses less space and is independent of timezone.
So, is there any reason, why Rails 3 uses “datetime” and not “timestamp”? Should I try to fix that? If yes, is there any way to do this besides not using “t.timestamps” and defining “updated_at” and “created_at” columns separately every time for each new table?
From memory, the mysql
timestampcolumn type behaves similar toupdated_atin that it is updated with the current time whenever the record is updated.While this is useful for the
updated_atcolumn, this is not the desired behaviour forcreated_at.In addition, Rails handles the timezone as specified in your app’s settings (should would normally be set to UTC), so using mysql’s time may be inconsistent with other datetime records.