From 14a75a54a802b35db5a7802eca90dae9aa8e3518 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 1 May 2013 21:24:43 -0300 Subject: [PATCH] Improve docs for postgresql with uuid primary keys [ci skip] Introduced in 09ac1776abc0d3482f491f2d49f47bcb3d9a4ad7. --- .../connection_adapters/postgresql_adapter.rb | 15 +++++++-------- .../test/cases/adapters/postgresql/uuid_test.rb | 1 - 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 6040eeed00..654aac8453 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -340,10 +340,10 @@ module ActiveRecord # end # # By default, this will use the +uuid_generate_v4()+ function from the - # +uuid-ossp+ extension, which MUST be enabled on your databse. To enable + # +uuid-ossp+ extension, which MUST be enabled on your database. To enable # the +uuid-ossp+ extension, you can use the +enable_extension+ method in your - # migrations To use a UUID primary key without +uuid-ossp+ enabled, you can - # set the +:default+ option to nil: + # migrations. To use a UUID primary key without +uuid-ossp+ enabled, you can + # set the +:default+ option to +nil+: # # create_table :stuffs, id: false do |t| # t.primary_key :id, :uuid, default: nil @@ -354,11 +354,10 @@ module ActiveRecord # You may also pass a different UUID generation function from +uuid-ossp+ # or another library. # - # Note that setting the UUID primary key default value to +nil+ - # will require you to assure that you always provide a UUID value - # before saving a record (as primary keys cannot be nil). This might be - # done via the SecureRandom.uuid method and a +before_save+ callback, - # for instance. + # Note that setting the UUID primary key default value to +nil+ will + # require you to assure that you always provide a UUID value before saving + # a record (as primary keys cannot be +nil+). This might be done via the + # +SecureRandom.uuid+ method and a +before_save+ callback, for instance. def primary_key(name, type = :primary_key, options = {}) return super unless type == :uuid options[:default] = options.fetch(:default, 'uuid_generate_v4()') diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb index edf18cb7a7..04c9065393 100644 --- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb +++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb @@ -59,7 +59,6 @@ class PostgresqlUUIDTestNilDefault < ActiveRecord::TestCase def setup @connection = ActiveRecord::Base.connection - @connection.reconnect! @connection.transaction do