tags:

views:

434

answers:

2

I tried the following yaml code:

columns:

 created_time:
   type: timestamp
   notnull: true
   default: default CURRENT_TIMESTAMP

In the outputted sql statement, the field is treated as datetime instead of timestamp, which I cannot define the current timestamp in it...

If I insist to use timestamp to store current time, how to do so in yaml?

A: 

You could use the 'Timestampable' functionality in doctrine, eg:

actAs:
  Timestampable:
    created:
      name: created_time
    updated:
      disabled: true
columns:
  created_time:
    type: timestamp
   notnull: true
Twelve47
A: 

Notice that "DEFAULT CURRENT_TIMESTAMP" does not work the same as Timestampable, and thus you cannot blindly exchange one for the other.

First and foremost, the former use the date/time of the DB server, while the latter use a Doctrine magic that calls PHP's date() function on your webserver. In other words, they are two distinct ways of getting the date/time, from two entirely differente clock sources. You may be on big trouble if you use Timestampable, your web servers run on different machines than your DB server, and you don't keep your clocks in sync using e.g. NTP.

Also, the "DEFAULT CURRENT_TIMESTAMP" being on the table definition makes for a much more consistent database model IMHO, as no matter how you insert the data (for instance, running INSERTs on the DB engine command line), you'll always get the current date/time on the column.

BTW, I'm also looking for an answer for the 'CURRENT_TIMESTAMP' problem mentioned on the initial question, as this is (due to the reasons outlined above) my preferred way of keeping "timestamp" columns.

Flávio