Class: ActiveRecord::ConnectionAdapters::MySQL::SchemaCreation
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActiveRecord::ConnectionAdapters::SchemaCreation
|
Defined in: | activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb |
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #add_sql_comment!
- #mariadb? ⇒ Boolean
- #add_column_options!(sql, options) private
- #add_column_position!(sql, options) private
- #add_table_options!(create_sql, o) private
- #index_in_create(table_name, column_name, options) private
- #visit_AddColumnDefinition(o) private
- #visit_ChangeColumnDefaultDefinition(o) private
- #visit_ChangeColumnDefinition(o) private
- #visit_CreateIndexDefinition(o) private
- #visit_DropCheckConstraint(name) private
- #visit_DropForeignKey(name) private
- #visit_IndexDefinition(o, create = false) private
::ActiveRecord::ConnectionAdapters::SchemaCreation
- Inherited
Constructor Details
This class inherits a constructor from ActiveRecord::ConnectionAdapters::SchemaCreation
Instance Method Details
#add_column_options!(sql, options) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 62
def (sql, ) # By default, TIMESTAMP columns are NOT NULL, cannot contain NULL values, # and assigning NULL assigns the current timestamp. To permit a TIMESTAMP # column to contain NULL, explicitly declare it with the NULL attribute. # See https://dev.mysql.com/doc/refman/en/timestamp-initialization.html if /\Atimestamp\b/.match?( [:column].sql_type) && ! [:primary_key] sql << " NULL" unless [:null] == false || ( ) end if charset = [:charset] sql << " CHARACTER SET #{charset}" end if collation = [:collation] sql << " COLLATE #{collation}" end if as = [:as] sql << " AS (#{as})" if [:stored] sql << (mariadb? ? " PERSISTENT" : " STORED") end end add_sql_comment!(super, [:comment]) end
#add_column_position!(sql, options) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 89
def add_column_position!(sql, ) if [:first] sql << " FIRST" elsif [:after] sql << " AFTER #{quote_column_name( [:after])}" end sql end
#add_sql_comment!
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 7
delegate :add_sql_comment!, :mariadb?, to: :@conn, private: true
#add_table_options!(create_sql, o) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 56
def (create_sql, o) create_sql << " DEFAULT CHARSET=#{o.charset}" if o.charset create_sql << " COLLATE=#{o.collation}" if o.collation add_sql_comment!(super, o.comment) end
#index_in_create(table_name, column_name, options) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 99
def index_in_create(table_name, column_name, ) index, _ = @conn. (table_name, column_name, ** ) accept(index) end
#mariadb? ⇒ Boolean
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 7
delegate :add_sql_comment!, :mariadb?, to: :@conn, private: true
#visit_AddColumnDefinition(o) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 18
def visit_AddColumnDefinition(o) add_column_position!(super, (o.column)) end
#visit_ChangeColumnDefaultDefinition(o) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 27
def visit_ChangeColumnDefaultDefinition(o) sql = +"ALTER COLUMN #{quote_column_name(o.column.name)} " if o.default.nil? && !o.column.null sql << "DROP DEFAULT" else sql << "SET DEFAULT #{quote_default_expression(o.default, o.column)}" end end
#visit_ChangeColumnDefinition(o) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 22
def visit_ChangeColumnDefinition(o) change_column_sql = +"CHANGE #{quote_column_name(o.name)} #{accept(o.column)}" add_column_position!(change_column_sql, (o.column)) end
#visit_CreateIndexDefinition(o) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 36
def visit_CreateIndexDefinition(o) sql = visit_IndexDefinition(o.index, true) sql << " #{o.algorithm}" if o.algorithm sql end
#visit_DropCheckConstraint(name) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 14
def visit_DropCheckConstraint(name) "DROP #{mariadb? ? 'CONSTRAINT' : 'CHECK'} #{name}" end
#visit_DropForeignKey(name) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 10
def visit_DropForeignKey(name) "DROP FOREIGN KEY #{name}" end
#visit_IndexDefinition(o, create = false) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb', line 42
def visit_IndexDefinition(o, create = false) index_type = o.type&.to_s&.upcase || o.unique && "UNIQUE" sql = create ? ["CREATE"] : [] sql << index_type if index_type sql << "INDEX" sql << quote_column_name(o.name) sql << "USING #{o.using}" if o.using sql << "ON #{quote_table_name(o.table)}" if create sql << "(#{quoted_columns(o)})" add_sql_comment!(sql.join(" "), o.comment) end