rails/rails — pull request #10404 by chadmoone (2013-05-01 21:44:25+00:00)
Title: Allow override of PostgreSQL UUID primary key default

bc8ebefe9825dbff2cffa29ff015a1e7a31f9812 adds the ability to define tables with primary keys which use PostgreSQL's native UUID type, which is pretty sweet :smile:.

However, because PostgreSQL does not itself provide a usable default value or UUID generator function, the`PostgreSQLAdapter` implementation sets the default value to `uuid_generate_v4()`, which is a function provided by an external extension (`uuid-ossp`) that is not enabled by default in PostgreSQL (it is also not supported by some distributions of PostgreSQL—notably Heroku's [Postgres.app](http://postgresapp.com/)).

This default can currently only be overridden by either passing another UUID generation function (which will also not be enabled by default), or passing an actual static UUID value, which is not appropriate for a primary key.

This patch allows the `:default` option on a table definition to be set to `nil`, which will set no default value.

Setting the default value to `nil` will require you to always generate a UUID before saving a record (likely in a model's or concern's `before_save` callback), but it will at least allow you to use the UUID primary key feature without extensions or external libraries.

I also tried to add a little documentation that will hopefully help people looking into this in the future. Please let me know if you have any feedback or suggestions.

*(Tagging @tenderlove, as this is the patch the he and I discussed in the rails-core mailing list.)*