Class: ActiveRecord::SchemaMigration

Inherits:
Base show all
Defined in:
activerecord/lib/active_record/schema_migration.rb

Constant Summary

Constants included from ConnectionHandling

ConnectionHandling::DEFAULT_ENV, ConnectionHandling::RAILS_ENV, ConnectionHandling::VALID_CONN_PARAMS

Constants included from Transactions

Transactions::ACTIONS, Transactions::CALLBACK_WARN_MESSAGE

Constants included from ActiveModel::SecurePassword

ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED

Constants included from Callbacks

Callbacks::CALLBACKS

Constants included from AttributeMethods

AttributeMethods::AttrNames, AttributeMethods::BLACKLISTED_CLASS_METHODS

Constants included from ActiveModel::AttributeMethods

ActiveModel::AttributeMethods::CALL_COMPILABLE_REGEXP, ActiveModel::AttributeMethods::NAME_COMPILABLE_REGEXP

Constants included from Attributes

Attributes::Type

Instance Attribute Summary

Attributes included from Associations

#association_cache

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Delegation::DelegateCache

#inherited, #initialize_relation_delegate_cache, #relation_delegate_class

Methods included from Enum

#enum, extended, #inherited

Methods included from Explain

#collecting_queries_for_explain, #exec_explain

Methods included from DynamicMatchers

#respond_to?

Methods included from Translation

#i18n_scope, #lookup_ancestors

Methods included from ActiveModel::Translation

#human_attribute_name, #i18n_scope, #lookup_ancestors

Methods included from ActiveModel::Naming

extended, #model_name, param_key, plural, route_key, singular, singular_route_key, uncountable?

Methods included from Querying

#count_by_sql, #find_by_sql

Methods included from QueryCache::ClassMethods

#cache, #uncached

Methods included from ConnectionHandling

#clear_cache!, #connected?, #connection, #connection_config, #connection_id, #connection_id=, #connection_pool, #establish_connection, #mysql2_connection, #mysql_connection, #postgresql_connection, #remove_connection, #retrieve_connection, #sqlite3_connection

Methods included from ActiveSupport::DescendantsTracker

clear, #descendants, descendants, #direct_descendants, direct_descendants, #inherited, store_inherited

Methods included from ActiveSupport::Benchmarkable

#benchmark

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included

Methods included from Serialization

#serializable_hash, #to_xml

Methods included from ActiveModel::Serializers::Xml

#from_xml, #to_xml

Methods included from ActiveModel::Serialization

#serializable_hash

Methods included from ActiveModel::Serializers::JSON

#as_json, #from_json

Methods included from Reflection

add_aggregate_reflection, add_reflection, create

Methods included from NoTouching

applied_to?, apply_to, #no_touching?, #touch

Methods included from Transactions

#add_to_transaction, #committed!, #destroy, #rollback_active_record_state!, #rolledback!, #save, #save!, #touch, #transaction, #with_transaction_returning_status

Methods included from Aggregations

#clear_aggregation_cache

Methods included from NestedAttributes

#_destroy

Methods included from AutosaveAssociation

#changed_for_autosave?, #destroyed_by_association, #destroyed_by_association=, #mark_for_destruction, #marked_for_destruction?, #reload

Methods included from Associations

#association, #clear_association_cache

Methods included from ActiveSupport::Autoload

#autoload, #autoload_at, #autoload_under, #autoloads, #eager_autoload, #eager_load!, extended

Methods included from Timestamp

#initialize_dup

Methods included from Callbacks

#destroy, #touch

Methods included from AttributeMethods

#[], #[]=, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #has_attribute?, #respond_to?

Methods included from ActiveModel::AttributeMethods

#attribute_missing, #method_missing, #respond_to?, #respond_to_without_attributes?

Methods included from Locking::Pessimistic

#lock!, #with_lock

Methods included from Locking::Optimistic

#locking_enabled?

Methods included from Validations

#save, #save!, #valid?, #validate!

Methods included from ActiveModel::Validations

#errors, #initialize_dup, #invalid?, #valid?, #validates_with

Methods included from Integration

#cache_key, #to_param

Methods included from ActiveModel::Conversion

#to_key, #to_model, #to_param, #to_partial_path

Methods included from AttributeAssignment

#assign_attributes

Methods included from Sanitization

#quoted_id

Methods included from Scoping

#initialize_internals_callback, #populate_with_current_scope_attributes

Methods included from Inheritance

#initialize_dup

Methods included from ModelSchema

derive_join_table_name

Methods included from Persistence

#becomes, #becomes!, #decrement, #decrement!, #delete, #destroy, #destroy!, #destroyed?, #increment, #increment!, #new_record?, #persisted?, #reload, #save, #save!, #toggle, #toggle!, #touch, #update, #update!, #update_attribute, #update_column, #update_columns

Methods included from Core

#<=>, #==, #connection_handler, #encode_with, #freeze, #frozen?, #hash, #init_with, #initialize, #initialize_dup, #inspect, #pretty_print, #readonly!, #readonly?, #slice

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveModel::AttributeMethods

Class Method Details

.create_table(limit = nil) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
# File 'activerecord/lib/active_record/schema_migration.rb', line 24

def create_table(limit=nil)
  unless table_exists?
    version_options = {null: false}
    version_options[:limit] = limit if limit

    connection.create_table(table_name, id: false) do |t|
      t.column :version, :string, version_options
    end
    connection.add_index table_name, :version, unique: true, name: index_name
  end
end

.drop_tableObject


36
37
38
# File 'activerecord/lib/active_record/schema_migration.rb', line 36

def drop_table
  connection.drop_table table_name if table_exists?
end

.index_nameObject


16
17
18
# File 'activerecord/lib/active_record/schema_migration.rb', line 16

def index_name
  "#{table_name_prefix}unique_#{ActiveRecord::Base.schema_migrations_table_name}#{table_name_suffix}"
end

.normalize_migration_number(number) ⇒ Object


40
41
42
# File 'activerecord/lib/active_record/schema_migration.rb', line 40

def normalize_migration_number(number)
  "%.3d" % number.to_i
end

.normalized_versionsObject


44
45
46
# File 'activerecord/lib/active_record/schema_migration.rb', line 44

def normalized_versions
  pluck(:version).map { |v| normalize_migration_number v }
end

.primary_keyObject


8
9
10
# File 'activerecord/lib/active_record/schema_migration.rb', line 8

def primary_key
  nil
end

.table_exists?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'activerecord/lib/active_record/schema_migration.rb', line 20

def table_exists?
  connection.table_exists?(table_name)
end

.table_nameObject


12
13
14
# File 'activerecord/lib/active_record/schema_migration.rb', line 12

def table_name
  "#{table_name_prefix}#{ActiveRecord::Base.schema_migrations_table_name}#{table_name_suffix}"
end

Instance Method Details

#versionObject


49
50
51
# File 'activerecord/lib/active_record/schema_migration.rb', line 49

def version
  super.to_i
end