Module: ActiveRecord::ConnectionAdapters::MySQL::SchemaStatements

Included in:
AbstractMysqlAdapter
Defined in:
activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#create_schema_dumper(options) ⇒ Object



69
70
71
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb', line 69

def create_schema_dumper(options)
  MySQL::SchemaDumper.create(self, options)
end

#indexes(table_name, name = nil) ⇒ Object

Returns an array of indexes for the given table.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb', line 8

def indexes(table_name, name = nil)
  if name
    ActiveSupport::Deprecation.warn("      Passing name to #indexes is deprecated without replacement.\n    MSG\n  end\n\n  indexes = []\n  current_index = nil\n  execute_and_free(\"SHOW KEYS FROM \#{quote_table_name(table_name)}\", \"SCHEMA\") do |result|\n    each_hash(result) do |row|\n      if current_index != row[:Key_name]\n        next if row[:Key_name] == \"PRIMARY\" # skip the primary key\n        current_index = row[:Key_name]\n\n        mysql_index_type = row[:Index_type].downcase.to_sym\n        case mysql_index_type\n        when :fulltext, :spatial\n          index_type = mysql_index_type\n        when :btree, :hash\n          index_using = mysql_index_type\n        end\n\n        indexes << IndexDefinition.new(\n          row[:Table],\n          row[:Key_name],\n          row[:Non_unique].to_i == 0,\n          type: index_type,\n          using: index_using,\n          comment: row[:Index_comment].presence\n        )\n      end\n\n      indexes.last.columns << row[:Column_name]\n      indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part]\n      indexes.last.orders.merge!(row[:Column_name] => :desc) if row[:Collation] == \"D\"\n    end\n  end\n\n  indexes\nend\n".squish)

#internal_string_options_for_primary_keyObject



57
58
59
60
61
62
63
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb', line 57

def internal_string_options_for_primary_key
  super.tap do |options|
    if CHARSETS_OF_4BYTES_MAXLEN.include?(charset) && (mariadb? || version < "8.0.0")
      options[:collation] = collation.sub(/\A[^_]+/, "utf8")
    end
  end
end

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



50
51
52
53
54
55
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb', line 50

def remove_column(table_name, column_name, type = nil, options = {})
  if foreign_key_exists?(table_name, column: column_name)
    remove_foreign_key(table_name, column: column_name)
  end
  super
end

#update_table_definition(table_name, base) ⇒ Object



65
66
67
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb', line 65

def update_table_definition(table_name, base)
  MySQL::Table.new(table_name, base)
end