This project is archived and is in readonly mode.
PostgreSQL add column behaves differently to other adaptors (SQlite, MySQL) when specifying default
-
Michael Granger
I'm not sure why your migrations aren't doing this, but PostgreSQL does set the default values on new columns in an ALTER TABLE:
$ psql test psql (9.0.3) Type "help" for help. test=> create table foo ( id serial, name text ); NOTICE: CREATE TABLE will create implicit sequence "foo_id_seq" for serial column "foo.id" CREATE TABLE test=> copy foo (name) from stdin; Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> Tricky >> Dicky >> Ricky >> Micky >> Maude >> \. test=> select * from foo; id | name ----+-------- 1 | Tricky 2 | Dicky 3 | Ricky 4 | Micky 5 | Maude (5 rows) test=> alter table foo add column signed boolean default false; ALTER TABLE test=> select * from foo; id | name | signed ----+--------+-------- 1 | Tricky | f 2 | Dicky | f 3 | Ricky | f 4 | Micky | f 5 | Maude | f (5 rows) -
John Barker
Rails actually sends separate commands to the database when you do an add_column, not a single alter table statement. Your example SQL alter table statement is the same behaviour introduced in my patch.
-
Michael Granger
I'm sorry, I must have read the diff backwards for some reason. Your patch modifies it to do exactly what I'd expect.
-
Juan Manuel Cuello
I think the patch was not created the way Rails Guides explains, so I cannot apply it for testing. Could you please re-create it?
-
John Barker
Just realised this was also fixed in master, so simply back-ported the fix and made the diff as per the guide, applied it with 'git am ...' and it works, passes all the rake tests.
