Dump the default nil for PostgreSQL UUID primary key.

This commit is contained in:
Ryuta Kamizono 2014-12-26 17:45:12 +09:00
parent 5fed875e90
commit 9b3e7b396e
3 changed files with 11 additions and 1 deletions

@ -1,3 +1,7 @@
* Dump the default `nil` for PostgreSQL UUID primary key.
*Ryuta Kamizono*
* Add a `:foreign_key` option to `references` and associated migration
methods. The model and migration generators now use this option, rather than
the `add_foreign_key` form.

@ -121,7 +121,7 @@ def table(table, stream)
tbl.print ", id: :bigserial"
elsif pkcol.sql_type == 'uuid'
tbl.print ", id: :uuid"
tbl.print %Q(, default: "#{pkcol.default_function}") if pkcol.default_function
tbl.print %Q(, default: #{pkcol.default_function.inspect})
end
else
tbl.print ", id: false"

@ -215,6 +215,7 @@ def test_schema_dumper_for_uuid_primary_key_with_custom_default
class PostgresqlUUIDTestNilDefault < ActiveRecord::TestCase
include PostgresqlUUIDHelper
include SchemaDumpingHelper
setup do
enable_extension!('uuid-ossp', connection)
@ -238,6 +239,11 @@ def test_id_allows_default_override_via_nil
WHERE a.attname='id' AND a.attrelid = 'pg_uuids'::regclass").first
assert_nil col_desc["default"]
end
def test_schema_dumper_for_uuid_primary_key_with_default_override_via_nil
schema = dump_table_schema "pg_uuids"
assert_match(/\bcreate_table "pg_uuids", id: :uuid, default: nil/, schema)
end
end
end