123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::ConnectionAdapters::SchemaDumper

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveRecord::SchemaDumper
Defined in: activerecord/lib/active_record/connection_adapters/abstract/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

Instance Attribute Summary

Instance Method Summary

Constructor Details

This class inherits a constructor from ActiveRecord::SchemaDumper

Class Method Details

.create(connection, options)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 8

def self.create(connection, options)
  new(connection, options)
end

Instance Method Details

#column_spec(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 13

def column_spec(column)
  [schema_type_with_virtual(column), prepare_column_options(column)]
end

#column_spec_for_primary_key(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 17

def column_spec_for_primary_key(column)
  spec = {}
  spec[:id] = schema_type(column).inspect unless default_primary_key?(column)
  spec.merge!(prepare_column_options(column).except!(:null))
  spec[:default] ||= "nil" if explicit_primary_key_default?(column)
  spec
end

#default_primary_key?(column) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 38

def default_primary_key?(column)
  schema_type(column) == :bigint
end

#explicit_primary_key_default?(column) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 42

def explicit_primary_key_default?(column)
  false
end

#prepare_column_options(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 25

def prepare_column_options(column)
  spec = {}
  spec[:limit] = schema_limit(column)
  spec[:precision] = schema_precision(column)
  spec[:scale] = schema_scale(column)
  spec[:default] = schema_default(column)
  spec[:null] = "false" unless column.null
  spec[:collation] = schema_collation(column)
  spec[:comment] = column.comment.inspect if column.comment.present?
  spec.compact!
  spec
end

#schema_collation(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 101

def schema_collation(column)
  column.collation.inspect if column.collation
end

#schema_default(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 86

def schema_default(column)
  return unless column.has_default?
  type = @connection.lookup_cast_type_from_column(column)
  default = type.deserialize(column.default)
  if default.nil?
    schema_expression(column)
  else
    type.type_cast_for_schema(default)
  end
end

#schema_expression(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 97

def schema_expression(column)
  "-> { #{column.default_function.inspect} }" if column.default_function
end

#schema_limit(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 62

def schema_limit(column)
  limit = column.limit unless column.bigint?
  limit.inspect if limit && limit != @connection.native_database_types[column.type][:limit]
end

#schema_precision(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 67

def schema_precision(column)
  if column.type == :datetime
    case column.precision
    when nil
      "nil"
    when DEFAULT_DATETIME_PRECISION
      nil
    else
      column.precision.inspect
    end
  elsif column.precision
    column.precision.inspect
  end
end

#schema_scale(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 82

def schema_scale(column)
  column.scale.inspect if column.scale
end

#schema_type(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 54

def schema_type(column)
  if column.bigint?
    :bigint
  else
    column.type
  end
end

#schema_type_with_virtual(column) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb', line 46

def schema_type_with_virtual(column)
  if @connection.supports_virtual_columns? && column.virtual?
    :virtual
  else
    schema_type(column)
  end
end