123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::ConnectionAdapters::MySQL::TableDefinition

Overview

Active Record MySQL Adapter Table Definition

Class Method Summary

Instance Attribute Summary

Instance Method Summary

ColumnMethods - Included

::ActiveRecord::ConnectionAdapters::TableDefinition - Inherited

#[]

Returns a ::ActiveRecord::ConnectionAdapters::ColumnDefinition for the column with name name.

#belongs_to
#blob, #check_constraint,
#column

Instantiates a new column for the table.

#columns

Returns an array of ::ActiveRecord::ConnectionAdapters::ColumnDefinition objects for the columns of the table.

#foreign_key,
#index

Adds index options to the indexes hash, keyed by column name This is primarily used to track indexes that need to be created after the table.

#numeric,
#references

Adds a reference.

#remove_column

remove the column name from the table.

#set_primary_key,
#timestamps

Appends :datetime columns :created_at and :updated_at to the table.

#aliased_types, #create_column_definition, #integer_like_primary_key?, #integer_like_primary_key_type, #raise_on_duplicate_column, #valid_column_definition_options, #new_check_constraint_definition, #new_column_definition, #new_foreign_key_definition, #primary_keys

::ActiveRecord::ConnectionAdapters::ColumnMethods - Included

#column

Appends a column or columns of a specified type.

#primary_key

Appends a primary key definition to the table definition.

Constructor Details

.new(conn, name, charset: nil, collation: nil) ⇒ TableDefinition

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb', line 60

def initialize(conn, name, charset: nil, collation: nil, **)
  super
  @charset = charset
  @collation = collation
end

Instance Attribute Details

#charset (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb', line 58

attr_reader :charset, :collation

#collation (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb', line 58

attr_reader :charset, :collation

Instance Method Details

#aliased_types(name, fallback) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb', line 87

def aliased_types(name, fallback)
  fallback
end

#integer_like_primary_key_type(type, options) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb', line 91

def integer_like_primary_key_type(type, options)
  unless options[:auto_increment] == false
    options[:auto_increment] = true
  end

  type
end

#new_column_definition(name, type, **options)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb', line 66

def new_column_definition(name, type, **options) # :nodoc:
  case type
  when :virtual
    type = options[:type]
  when :primary_key
    type = :integer
    options[:limit] ||= 8
    options[:primary_key] = true
  when /\Aunsigned_(?<type>.+)\z/
    type = $~[:type].to_sym
    options[:unsigned] = true
  end

  super
end

#valid_column_definition_options (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb', line 83

def valid_column_definition_options
  super + [:auto_increment, :charset, :as, :size, :unsigned, :first, :after, :type, :stored]
end