How can I change the (default) type for ActiveRecord\'s IDs? int is not long enough, I would prefer long. I was surprised that there is no :long for the migrations - does on
In rails4
, you can do it.
Following is an example to create a Dummy
model in rails4
& postgres
,
xxx_migrate_dummies.rb:
class CreateDummies < ActiveRecord::Migration
def change
create_table :dummies, :id => false do |t|
t.column :id, :serial8, primary_key: true
t.string :name, :limit => 50, null: false
t.integer :size, null: false
t.column :create_date, :timestamptz, null: false
end
end
end
What it did:
serial8
as id type, which is 64 bit integer, and define it as primary key
.timestamptz
as datetime type, which contain the timezone info, this is important for a application that go across multiple timezones.