전역 오염에 의한 알 수 없는 오류가 걱정된다면 ActiveRecord::Timestamp 모듈로 스코프를 조정하거나 필요한 부분에 일일히 to_ms를 써주어도 되지만,
귀찮으니 전역에 적용하도록 하자. 일단 적어도 루비 온 레일즈와 관련 잼들에서는 문제가 없음을 확인하였다.
ActiveRecord 타임스탬프의 타입 변경하기
타임스탬프 기능에서 중요한 것은 어차피 created_at, created_on, updated_at, updated_on 이라는 컬럼 이름이기에 위와 같이 생성 시 타입만 변경하는 것으로도 잘 동작한다. (포맷 스트링을 찍는 대신 암묵적으로 #to_i()를 사용한다.)
다만 이게 귀찮고 이전처럼 t.timestamps만 사용하고 싶다면 아래와 같이 initializer에 코드를 추가한다.
create_table :users |t| do
t.bigint :created_at, null: false
t.bigint :updated_at, null: false
end
module ActiveRecord
module ConnectionAdapters
class TableDefinition
def timestamps(**options)
options[:null] = false if options[:null].nil?
column(:created_at, :bigint, options)
column(:updated_at, :bigint, options)
end
end
end
end