Class: ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
- 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
- #add_column_sql(table_name, column_name, type, options = {}) ⇒ Object
- #change_column_sql(table_name, column_name, type, options = {}) ⇒ Object
- #create_table_definition(name, temporary, options) ⇒ Object
- #migration_keys ⇒ Object
-
#prepare_column_options(column, types) ⇒ Object
:nodoc:.
- #schema_creation ⇒ Object
- #type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = false) ⇒ Object
- #type_to_sql_without_unsigned ⇒ Object
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, = {}) td = create_table_definition table_name, [:temporary], [:options] cd = td.new_column_definition(column_name, type, ) 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, = {}) column = column_for(table_name, column_name) unless () [:default] = column.default end unless .has_key?(:null) [:null] = column.null end [:name] = column.name schema_creation.visit_ChangeColumnDefinition ChangeColumnDefinition.new column, type, 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, ) TableDefinition.new self end |
#migration_keys ⇒ Object
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 (column, types) # :nodoc: spec = super spec[:unsigned] = 'true' if column.unsigned? spec end |
#schema_creation ⇒ Object
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_unsigned ⇒ Object
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 |