aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb47
1 files changed, 15 insertions, 32 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..f17f1d35e2 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require "active_support/core_ext/hash/compact"
+
module ActiveRecord
module ConnectionAdapters # :nodoc:
# The goal of this module is to move Adapter specific column
@@ -20,38 +22,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 +29,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 +80,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?