Class: ActiveRecord::ConnectionAdapters::TableDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract/schema_definitions.rb,
lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract/schema_definitions.rb

Instance Method Summary collapse

Instance Method Details

#column(name, type, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract/schema_definitions.rb', line 29

def column(name, type, options = {})
  name = name.to_s
  type = type.to_sym

  column = self[name] || new_column_definition(@base, name, type)

  limit = options.fetch(:limit) do
    native[type][:limit] if native[type].is_a?(Hash)
  end

  column.limit          = limit
  column.unsigned       = options[:unsigned]
  column.auto_increment = options[:auto_increment]
  column.precision      = options[:precision]
  column.scale          = options[:scale]
  column.default        = options[:default]
  column.null           = options[:null]
  self
end

#new_column_definition(name, type, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract/schema_definitions.rb', line 19

def new_column_definition(name, type, options)
  column = create_column_definition name, type
  limit = options.fetch(:limit) do
    native[type][:limit] if native[type].is_a?(Hash)
  end

  column.limit       = limit
  column.array       = options[:array] if column.respond_to?(:array)
  column.precision   = options[:precision]
  column.scale       = options[:scale]
  column.unsigned    = options[:unsigned]
  column.default     = options[:default]
  column.null        = options[:null]
  column.first       = options[:first]
  column.after       = options[:after]
  column.primary_key = type == :primary_key || options[:primary_key]
  column
end