diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-08-21 00:44:50 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-08-21 00:44:50 +0900 |
commit | 8170419b0a0e7abbfb2c64c84f641c0a39c163d0 (patch) | |
tree | c22309324058b8114786801ac5a7f0c20cb701a0 /activerecord | |
parent | dcf7fc1047946e6759c8346a331718e5555f04f1 (diff) | |
download | rails-8170419b0a0e7abbfb2c64c84f641c0a39c163d0.tar.gz rails-8170419b0a0e7abbfb2c64c84f641c0a39c163d0.tar.bz2 rails-8170419b0a0e7abbfb2c64c84f641c0a39c163d0.zip |
Don't expose `prepare_column_options`
This is only used for the internal `column_spec` and
`column_spec_for_primary_key`.
Diffstat (limited to 'activerecord')
3 files changed, 30 insertions, 52 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb index 9be26254b2..56df76caf3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb @@ -20,38 +20,6 @@ module ActiveRecord spec end - # This can be overridden on an Adapter level basis to support other - # extended datatypes (Example: Adding an array option in the - # PostgreSQL::ColumnDumper) - def prepare_column_options(column) - spec = {} - - if limit = schema_limit(column) - spec[:limit] = limit - end - - if precision = schema_precision(column) - spec[:precision] = precision - end - - if scale = schema_scale(column) - spec[:scale] = scale - end - - default = schema_default(column) if column.has_default? - spec[:default] = default unless default.nil? - - spec[:null] = "false" unless column.null - - if collation = schema_collation(column) - spec[:collation] = collation - end - - spec[:comment] = column.comment.inspect if column.comment.present? - - spec - end - # Lists the valid migration options def migration_keys # :nodoc: column_options_keys @@ -59,6 +27,18 @@ module ActiveRecord deprecate :migration_keys private + def prepare_column_options(column) + spec = {} + spec[:limit] = schema_limit(column) + spec[:precision] = schema_precision(column) + spec[:scale] = schema_scale(column) + spec[:default] = schema_default(column) + spec[:null] = "false" unless column.null + spec[:collation] = schema_collation(column) + spec[:comment] = column.comment.inspect if column.comment.present? + spec.compact! + spec + end def default_primary_key?(column) schema_type(column) == :bigint @@ -98,6 +78,7 @@ module ActiveRecord end def schema_default(column) + return unless column.has_default? type = lookup_cast_type_from_column(column) default = type.deserialize(column.default) if default.nil? diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb index fbe3596dda..81f7dce562 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb @@ -4,24 +4,23 @@ module ActiveRecord module ConnectionAdapters module MySQL module ColumnDumper # :nodoc: - def prepare_column_options(column) - spec = super - spec[:unsigned] = "true" if column.unsigned? - - if supports_virtual_columns? && column.virtual? - spec[:as] = extract_expression_for_virtual_column(column) - spec[:stored] = "true" if /\b(?:STORED|PERSISTENT)\b/.match?(column.extra) - spec = { type: schema_type(column).inspect }.merge!(spec) - end - - spec - end - def migration_keys super + [:unsigned] end private + def prepare_column_options(column) + spec = super + spec[:unsigned] = "true" if column.unsigned? + + if supports_virtual_columns? && column.virtual? + spec[:as] = extract_expression_for_virtual_column(column) + spec[:stored] = "true" if /\b(?:STORED|PERSISTENT)\b/.match?(column.extra) + spec = { type: schema_type(column).inspect }.merge!(spec) + end + + spec + end def default_primary_key?(column) super && column.auto_increment? && !column.unsigned? 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 12c6603081..5031605c2a 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb @@ -4,19 +4,17 @@ module ActiveRecord module ConnectionAdapters module PostgreSQL module ColumnDumper # :nodoc: - # Adds +:array+ option to the default set - def prepare_column_options(column) - spec = super - spec[:array] = "true" if column.array? - spec - end - # Adds +:array+ as a valid migration key def migration_keys super + [:array] end private + def prepare_column_options(column) + spec = super + spec[:array] = "true" if column.array? + spec + end def default_primary_key?(column) schema_type(column) == :bigserial |