Class: ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter

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

Defined Under Namespace

Classes: ChangeColumnDefinition, Column, SchemaCreation, TableDefinition

Instance Method Summary collapse

Instance Method Details

#add_column_sql(table_name, column_name, type, options = {}) ⇒ Object



97
98
99
100
101
# File 'lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract_mysql_adapter.rb', line 97

def add_column_sql(table_name, column_name, type, options = {})
  td = create_table_definition table_name, options[:temporary], options[:options]
  cd = td.new_column_definition(column_name, type, options)
  schema_creation.visit_AddColumn cd
end

#change_column_sql(table_name, column_name, type, options = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract_mysql_adapter.rb', line 103

def change_column_sql(table_name, column_name, type, options = {})
  column = column_for(table_name, column_name)

  unless options_include_default?(options)
    options[:default] = column.default
  end

  unless options.has_key?(:null)
    options[:null] = column.null
  end

  options[:name] = column.name
  schema_creation.visit_ChangeColumnDefinition ChangeColumnDefinition.new column, type, options
end

#create_table_definition(name, temporary, options) ⇒ Object



44
45
46
# File 'lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract_mysql_adapter.rb', line 44

def create_table_definition(name, temporary, options)
  TableDefinition.new self
end

#migration_keysObject



71
72
73
# File 'lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract_mysql_adapter.rb', line 71

def migration_keys
  super + [:unsigned]
end

#prepare_column_options(column, types) ⇒ Object

:nodoc:



65
66
67
68
69
# File 'lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract_mysql_adapter.rb', line 65

def prepare_column_options(column, types) # :nodoc:
  spec = super
  spec[:unsigned] = 'true' if column.unsigned?
  spec
end

#schema_creationObject



40
41
42
# File 'lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract_mysql_adapter.rb', line 40

def schema_creation
  SchemaCreation.new self
end

#type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = false) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract_mysql_adapter.rb', line 76

def type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = false)
  case type.to_s
  when 'integer'
    case limit
    when nil, 4, 11; 'int'  # compatibility with MySQL default
    else
      type_to_sql_without_unsigned(type, limit, precision, scale)
    end.tap do |sql_type|
      sql_type << ' unsigned' if unsigned
    end
  when 'float', 'decimal'
    type_to_sql_without_unsigned(type, limit, precision, scale).tap do |sql_type|
      sql_type << ' unsigned' if unsigned
    end
  when 'primary_key'
    "#{type_to_sql(:integer, limit, precision, scale, unsigned)} auto_increment PRIMARY KEY"
  else
    type_to_sql_without_unsigned(type, limit, precision, scale)
  end
end

#type_to_sql_without_unsignedObject



75
# File 'lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract_mysql_adapter.rb', line 75

alias_method :type_to_sql_without_unsigned, :type_to_sql