Module: ActiveRecord::ConnectionAdapters::ColumnDumper

Included in:
AbstractAdapter
Defined in:
activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb

Overview

The goal of this module is to move Adapter specific column definitions to the Adapter instead of having it in the schema dumper itself. This code represents the normal case. We can then redefine how certain data types may be handled in the schema dumper on the Adapter level by over-writing this code inside the database specific adapters

Instance Method Summary collapse

Instance Method Details

#column_spec(column, types) ⇒ Object


9
10
11
12
13
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 9

def column_spec(column, types)
  spec = prepare_column_options(column, types)
  (spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, "#{k}: ")}
  spec
end

#migration_keysObject

Lists the valid migration options


36
37
38
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 36

def migration_keys
  [:name, :limit, :precision, :scale, :default, :null]
end

#prepare_column_options(column, types) ⇒ Object

This can be overridden on a Adapter level basis to support other extended datatypes (Example: Adding an array option in the PostgreSQLAdapter)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 18

def prepare_column_options(column, types)
  spec = {}
  spec[:name]      = column.name.inspect
  spec[:type]      = column.type.to_s
  spec[:null]      = 'false' unless column.null

  limit = column.limit || types[column.type][:limit]
  spec[:limit]     = limit.inspect if limit
  spec[:precision] = column.precision.inspect if column.precision
  spec[:scale]     = column.scale.inspect if column.scale

  default = schema_default(column) if column.has_default?
  spec[:default]   = default unless default.nil?

  spec
end