diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-02-12 07:26:05 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-03-11 14:43:20 +0900 |
commit | 270bcebdf79fd033e8451a2b6ab1c3db1dfb87b2 (patch) | |
tree | 2feb914887aa64094e8af50011dbd4d0ba95e95a /activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb | |
parent | a101115d5b8011278891f30f69901f9583ea7685 (diff) | |
download | rails-270bcebdf79fd033e8451a2b6ab1c3db1dfb87b2.tar.gz rails-270bcebdf79fd033e8451a2b6ab1c3db1dfb87b2.tar.bz2 rails-270bcebdf79fd033e8451a2b6ab1c3db1dfb87b2.zip |
Extract `default_primary_key?` to refactor `column_spec_for_primary_key`
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb index 5cb2bbbf18..8c983f240c 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb @@ -3,16 +3,9 @@ module ActiveRecord module PostgreSQL module ColumnDumper def column_spec_for_primary_key(column) - spec = {} - if column.serial? - return unless column.bigint? - spec[:id] = ':bigserial' - elsif column.type == :uuid - spec[:id] = ':uuid' - spec[:default] = schema_default(column) || 'nil' - else - spec[:id] = schema_type(column).inspect - spec.merge!(prepare_column_options(column).delete_if { |key, _| key == :null }) + spec = super.except!(:null) + if schema_type(column) == :uuid + spec[:default] ||= 'nil' end spec end @@ -31,6 +24,10 @@ module ActiveRecord private + def default_primary_key?(column) + schema_type(column) == :serial + end + def schema_type(column) return super unless column.serial? |