Class: ActiveRecord::ConnectionAdapters::MySQL::SchemaDumper
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActiveRecord::ConnectionAdapters::SchemaDumper
|
Defined in: | activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb |
Constant Summary
Class Attribute Summary
::ActiveRecord::SchemaDumper
- Inherited
.chk_ignore_pattern | Specify a custom regular expression matching check constraints which name should not be dumped to db/schema.rb. |
.excl_ignore_pattern | Specify a custom regular expression matching exclusion constraints which name should not be dumped to db/schema.rb. |
.fk_ignore_pattern | Specify a custom regular expression matching foreign keys which name should not be dumped to db/schema.rb. |
.ignore_tables | A list of tables which should not be dumped to the schema. |
.unique_ignore_pattern | Specify a custom regular expression matching unique constraints which name should not be dumped to db/schema.rb. |
Class Method Summary
::ActiveRecord::ConnectionAdapters::SchemaDumper
- Inherited
::ActiveRecord::SchemaDumper
- Inherited
Instance Attribute Summary
::ActiveRecord::SchemaDumper
- Inherited
Instance Method Summary
- #column_spec_for_primary_key(column) private
- #default_primary_key?(column) ⇒ Boolean private
- #explicit_primary_key_default?(column) ⇒ Boolean private
- #extract_expression_for_virtual_column(column) private
- #prepare_column_options(column) private
- #schema_collation(column) private
- #schema_limit(column) private
- #schema_precision(column) private
- #schema_type(column) private
::ActiveRecord::ConnectionAdapters::SchemaDumper
- Inherited
::ActiveRecord::SchemaDumper
- Inherited
#dump, #check_constraints_in_create, #define_params, | |
#extensions | extensions are only supported by |
#foreign_keys, #format_colspec, #format_index_parts, #format_options, | |
#formatted_version | turns 20170404131909 into “2017_04_04_131909”. |
#header, #ignored?, #index_parts, | |
#indexes | Keep it for indexing materialized views. |
#indexes_in_create, #remove_prefix_and_suffix, | |
#schemas | schemas are only supported by |
#table, #tables, #trailer, | |
#types | (enum) types are only supported by |
#virtual_tables | virtual tables are only supported by SQLite. |
Constructor Details
This class inherits a constructor from ActiveRecord::SchemaDumper
Instance Method Details
#column_spec_for_primary_key(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 26
def column_spec_for_primary_key(column) spec = super spec.delete(:auto_increment) if column.type == :integer && column.auto_increment? spec end
#default_primary_key?(column) ⇒ Boolean
(private)
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 32
def default_primary_key?(column) super && column.auto_increment? && !column.unsigned? end
#explicit_primary_key_default?(column) ⇒ Boolean
(private)
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 36
def explicit_primary_key_default?(column) column.type == :integer && !column.auto_increment? end
#extract_expression_for_virtual_column(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 74
def extract_expression_for_virtual_column(column) if @connection.mariadb? && @connection.database_version < "10.2.5" create_table_info = @connection.send(:create_table_info, table_name) column_name = @connection.quote_column_name(column.name) if %r/#{column_name} #{Regexp.quote(column.sql_type)}(?: COLLATE \w+)? AS \((?<expression>.+?)\) #{column.extra}/ =~ create_table_info $~[:expression].inspect end else scope = @connection.send(:quoted_scope, table_name) column_name = @connection.quote(column.name) sql = "SELECT generation_expression FROM information_schema.columns" \ " WHERE table_schema = #{scope[:schema]}" \ " AND table_name = #{scope[:name]}" \ " AND column_name = #{column_name}" # Calling .inspect leads into issues with the query result # which already returns escaped quotes. # We remove the escape sequence from the result in order to deal with double escaping issues. @connection.query_value(sql, "SCHEMA").gsub("\\'", "'").inspect end end
#prepare_column_options(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 8
def (column) spec = super spec[:unsigned] = "true" if column.unsigned? spec[:auto_increment] = "true" if column.auto_increment? if /\A(?<size>tiny|medium|long)(?:text|blob)/ =~ column.sql_type spec = { size: size.to_sym.inspect }.merge!(spec) end if @connection.supports_virtual_columns? && column.virtual? spec[:as] = extract_expression_for_virtual_column(column) spec[:stored] = "true" if /\b(?:STORED|PERSISTENT)\b/.match?(column.extra) spec = { type: schema_type(column).inspect }.merge!(spec) end spec end
#schema_collation(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 65
def schema_collation(column) if column.collation @table_collation_cache ||= {} @table_collation_cache[table_name] ||= @connection.internal_exec_query("SHOW TABLE STATUS LIKE #{@connection.quote(table_name)}", "SCHEMA").first["Collation"] column.collation.inspect if column.collation != @table_collation_cache[table_name] end end
#schema_limit(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 51
def schema_limit(column) super unless /\A(?:tiny|medium|long)?(?:text|blob)\b/.match?(column.sql_type) end
#schema_precision(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 55
def schema_precision(column) if /\Atime(?:stamp)?\b/.match?(column.sql_type) && column.precision == 0 nil elsif column.type == :datetime column.precision == 0 ? "nil" : super else super end end
#schema_type(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb', line 40
def schema_type(column) case column.sql_type when /\Atimestamp\b/ : when /\A(?:enum|set)\b/ column.sql_type else super end end