Dump the default function when the primary key is uuid

Fixes #12489
This commit is contained in:
Rafael Mendonça França 2013-10-14 00:56:30 -03:00
parent 2384148cbe
commit 9541a72858
2 changed files with 3 additions and 2 deletions

@ -123,6 +123,7 @@ def table(table, stream)
tbl.print %Q(, primary_key: "#{pk}")
elsif pkcol.sql_type == 'uuid'
tbl.print ", id: :uuid"
tbl.print %Q(, default: "#{pkcol.default_function}") if pkcol.respond_to?(:default_function) && pkcol.default_function
end
else
tbl.print ", id: false"

@ -24,7 +24,7 @@ def setup
@connection.reconnect!
@connection.transaction do
@connection.create_table('pg_uuids', id: :uuid) do |t|
@connection.create_table('pg_uuids', id: :uuid, default: 'uuid_generate_v1()') do |t|
t.string 'name'
t.uuid 'other_uuid', default: 'uuid_generate_v4()'
end
@ -60,7 +60,7 @@ def test_pk_and_sequence_for_uuid_primary_key
def test_schema_dumper_for_uuid_primary_key
schema = StringIO.new
ActiveRecord::SchemaDumper.dump(@connection, schema)
assert_match(/\bcreate_table "pg_uuids", id: :uuid\b/, schema.string)
assert_match(/\bcreate_table "pg_uuids", id: :uuid, default: "uuid_generate_v1\(\)"/, schema.string)
assert_match(/t\.uuid "other_uuid", default: "uuid_generate_v4\(\)"/, schema.string)
end
end