[rails]
[migration]
migration を用いて、mysql の timestamp 型のカラムを含むテーブルを作ろうと下記のようなコードを書きました。
class MigTests < ActiveRecord::Migration
def self.up
create_table :migtests do |t|
t.column :last_update, :timestamp
end
end
def self.down
drop_table :migtests
end
end
で、実行してみるがここで問題発生。
作成されるテーブルの last_update カラムがDATETIME型になる。
で、少し調べてみると、
activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb
にある、native_database_types というメソッド内に定義されたHashで、型名をシンボルからデータベースのカラムタイプ名に変換しているようです。
{
:timestamp => { :name => "datetime" },
}
なんであえて timestamp 型を使ってないんだろう・・・
なにか事情があるのだろうか。
さらに調査してみる。
チケットを発見。
http://dev.rubyonrails.org/ticket/4351
WONTFIXになってる。
* status changed from new to closed.
* resolution set to wontfix.
timestamps are turned back into datetimes when rows are initialized, so we've basically just decided that timestamps are a bad idea. Instead you should use things like created_on/at and updated_on/at.
timestamp型は bad idea らしいです。
update_on/at create_on/at を使えと。
そんなマジックカラムがあるのか・・・知らなかった。
参考URL