Module: ActiveRecord::ConnectionAdapters::ColumnDumper

Included in:
AbstractAdapter
Defined in:
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) ⇒ Object



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

def column_spec(column)
  [schema_type_with_virtual(column), prepare_column_options(column)]
end

#column_spec_for_primary_key(column) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 13

def column_spec_for_primary_key(column)
  return {} if default_primary_key?(column)
  spec = { id: schema_type(column).inspect }
  spec.merge!(prepare_column_options(column).except!(:null))
  spec[:default] ||= "nil" if explicit_primary_key_default?(column)
  spec
end

#migration_keysObject

Lists the valid migration options



54
55
56
# File 'lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 54

def migration_keys # :nodoc:
  column_options_keys
end

#prepare_column_options(column) ⇒ Object

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 24

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