How annoying is it that Rails doesn't do what you tell it, but tries to be smart? Trying to use custom DB logic in a Rails migration:
create_table :foos do |t|
t.timestamp :inserted_time, null: false, default: 'now()'
end
Results in this:
CREATE TABLE foos (
id integer NOT NULL,
inserted_time timestamp without time zone DEFAULT '2015-01-03 22:44:59.430585'::timestamp without time zone NOT NULL
);
Having to drop to raw SQL due to avoid the cleverness is annoying.
create_table :foos do |t|
t.timestamp :inserted_time, null: false
end
execute <<-SQL
ALTER TABLE foos
ALTER COLUMN inserted_time SET DEFAULT now()::timestamp;
SQL
CREATE TABLE foos (
id integer NOT NULL,
inserted_time timestamp without time zone DEFAULT (now())::timestamp without time zone NOT NULL
);