Created
March 3, 2014 20:46
-
-
Save searls/9334294 to your computer and use it in GitHub Desktop.
Setting a default timestamp to "now" in postgresql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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