Skip to content

Instantly share code, notes, and snippets.

@searls
Created March 3, 2014 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searls/9334294 to your computer and use it in GitHub Desktop.
Save searls/9334294 to your computer and use it in GitHub Desktop.
Setting a default timestamp to "now" in postgresql
class CreateMessages < ActiveRecord::Migration
def change
create_table :messages do |t|
t.references :chat
t.text :content
t.timestamp :received_at, :default => "now"
t.timestamps
end
end
end
class CreateMessages < ActiveRecord::Migration
def change
create_table :messages do |t|
t.references :chat
t.text :content
t.timestamp :received_at
t.timestamps
end
ActiveRecord::Base.connection.execute "ALTER TABLE messages ALTER COLUMN received_at SET DEFAULT now()"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment