123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::SchemaMigration

Constant Summary

::ActiveModel::AttributeMethods - Included

CALL_COMPILABLE_REGEXP, NAME_COMPILABLE_REGEXP

AttributeMethods - Included

AttrNames, BLACKLISTED_CLASS_METHODS

AttributeMethods::Read - Inherited

ID, ReaderMethodCache

AttributeMethods::Write - Inherited

WriterMethodCache

Callbacks - Included

CALLBACKS

::ActiveModel::SecurePassword - Included

MAX_PASSWORD_LENGTH_ALLOWED

Class Attribute Summary

Base - Inherited

._attr_readonly, ._attr_readonly?, ._reflections, ._reflections?, .aggregate_reflections, .aggregate_reflections?, .attribute_type_decorations, .attribute_type_decorations?, .cache_timestamp_format, .cache_timestamp_format?,
.configurations

Returns fully resolved configurations hash.

.configurations=

Contains the database configuration - as is typically stored in config/database.yml - as a ::Hash.

.connection_handler, .connection_handler=, .default_connection_handler, .default_connection_handler?,
.default_timezone

Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling dates and times from the database.

.disable_implicit_join_references=,
.dump_schema_after_migration

Specify whether schema dump should happen at the end of the db:migrate rake task.

.find_by_statement_cache, .find_by_statement_cache?, .local_stored_attributes, .lock_optimistically, .lock_optimistically?,
.logger

Accepts a logger conforming to the interface of Log4r which is then passed on to any new database connections made and which can be retrieved on both a class and instance level by calling logger.

.maintain_test_schema, .nested_attributes_options, .nested_attributes_options?, .pluralize_table_names, .pluralize_table_names?,
.primary_key_prefix_type

Accessor for the prefix type that will be prepended to every primary key column name.

.raise_in_transactional_callbacks, .record_timestamps, .record_timestamps?,
.schema_format

Specifies the format to use when dumping the database schema with Rails' Rakefile.

.schema_migrations_table_name, .schema_migrations_table_name?, .store_full_sti_class, .store_full_sti_class?, .table_name_prefix, .table_name_prefix?, .table_name_suffix, .table_name_suffix?,
.timestamped_migrations

Specify whether or not to use timestamps for migration versions.

.user_provided_columns, .user_provided_columns?, .user_provided_defaults, .user_provided_defaults?

Querying - Extended

ConnectionHandling - Extended

connected?

Returns true if Active Record is connected.

connection_id, connection_id=

Class Method Summary

Base - Inherited

Delegation::DelegateCache - Extended

Enum - Extended

::ActiveModel::Translation - Included

human_attribute_name

Transforms attribute names into a more human format, such as “First name” instead of “first_name”.

i18n_scope

Returns the i18n_scope for the class.

lookup_ancestors

When localizing a string, it goes through the lookup returned by this method, which is used in ActiveModel::Name#human, ActiveModel::Errors#full_messages and ActiveModel::Translation#human_attribute_name.

Querying - Extended

any?,
count_by_sql

Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part.

exists?, fifth!, find_by!,
find_by_sql

Executes a custom SQL query against your database and returns all the results.

find_or_create_by!, first!, first_or_create!, forty_two!, fourth!, last!, many?, second!, take!, third!

QueryCache::ClassMethods - Extended

cache

Enable the query cache within the block if Active Record is configured.

uncached

Disable the query cache within the block if Active Record is configured.

ConnectionHandling - Extended

clear_active_connections!, clear_all_connections!, clear_reloadable_connections!,
connection

Returns the connection currently associated with the class.

connection_config

Returns the configuration of the associated connection as a hash:

connection_pool,
establish_connection

Establishes the connection to the database.

remove_connection, retrieve_connection

::ActiveSupport::DescendantsTracker - Extended

::ActiveSupport::Benchmarkable - Extended

benchmark

Allows you to measure the execution time of a block in a template and records the result to the log.

::ActiveModel::Naming - Extended

model_name

Returns an ::ActiveModel::Name object for module.

Instance Attribute Summary

Base - Inherited

Serialization - Included

NoTouching - Included

AutosaveAssociation - Included

#changed_for_autosave?

Returns whether or not this record has been changed in any way (including whether any of its nested autosave associations are likewise changed).

#destroyed_by_association

Returns the association for the parent being destroyed.

#destroyed_by_association=

Records the association that is being destroyed and destroying this record in the process.

#marked_for_destruction?

Returns whether or not this record will be destroyed as part of the parents save transaction.

::ActiveModel::Dirty - Included

#attribute_aliases, #attribute_aliases?, #attribute_method_matchers, #attribute_method_matchers?,
#changed?

Returns true if any attribute have unsaved changes, false otherwise.

AttributeMethods::PrimaryKey - Inherited

#id

Returns the primary key value.

#id=

Sets the primary key value.

#id?

Queries the primary key value.

AttributeMethods - Included

Validations - Included

AttributeAssignment - Included

Persistence - Included

#destroyed?

Returns true if this object has been destroyed, otherwise returns false.

#new_record?

Returns true if this object hasn't been saved yet – that is, a record for the object doesn't exist in the database yet; otherwise, returns false.

#persisted?

Returns true if the record is persisted, i.e.

Core - Included

#frozen?

Returns true if the attributes hash has been frozen.

#readonly?

Returns true if the record is read only.

Instance Method Summary

Serialization - Included

#serializable_hash,
#to_xml

Builds an XML document to represent the model.

::ActiveModel::Serializers::Xml - Included

#from_xml

Sets the model attributes from an XML string.

#to_xml

Returns XML representing the model.

::ActiveModel::Serializers::JSON - Included

#as_json

Returns a hash representing the model.

#from_json

Sets the model attributes from a JSON string.

::ActiveModel::Serialization - Included

#serializable_hash

Returns a serialized hash of your object.

Transactions - Included

#add_to_transaction

Add the record to the current transaction so that the after_rollback and after_commit callbacks can be called.

#rollback_active_record_state!

Reset id and @new_record if the transaction rolls back.

#transaction

See Transactions::ClassMethods for detailed documentation.

#with_transaction_returning_status

Executes method within a transaction and captures its return value as a status flag.

AutosaveAssociation - Included

#mark_for_destruction

Marks this record to be destroyed as part of the parents save transaction.

#reload

Reloads the attributes of the object as usual and clears marked_for_destruction flag.

::ActiveModel::Dirty - Included

#changed

Returns an array with the name of the attributes with unsaved changes.

#changed_attributes

Returns a hash of the attributes with unsaved changes indicating their original values like attr => original value.

#changes

Returns a hash of changed attributes indicating their original and new values like attr => [original value, new value].

#previous_changes

Returns a hash of attributes that were changed before the model was saved.

#restore_attributes

Restore all previous data of the provided attributes.

#changes_applied

Removes current changes and makes them accessible through previous_changes.

#clear_attribute_changes

Remove changes information for the provided attributes.

#clear_changes_information

Clear all dirty data: current changes and previous changes.

AttributeMethods::PrimaryKey - Inherited

#id_before_type_cast

Returns the primary key value before type cast.

#id_was

Returns the primary key previous value.

#to_key

Returns this record's primary key value wrapped in an ::Array if one is available.

AttributeMethods::Query - Inherited

AttributeMethods::BeforeTypeCast - Inherited

#attributes_before_type_cast

Returns a hash of attributes before typecasting and deserialization.

#read_attribute_before_type_cast

Returns the value of the attribute identified by attr_name before typecasting and deserialization.

AttributeMethods::Write - Inherited

#raw_write_attribute,
#write_attribute

Updates the attribute identified by attr_name with the specified value.

AttributeMethods::Read - Inherited

#read_attribute

Returns the value of the attribute identified by attr_name after it has been typecast (for example, “2004-12-12” in a date column is cast to a date object, like Date.new(2004, 12, 12)).

AttributeMethods - Included

#[]

Returns the value of the attribute identified by attr_name after it has been typecast (for example, “2004-12-12” in a date column is cast to a date object, like Date.new(2004, 12, 12)).

#[]=

Updates the attribute identified by attr_name with the specified value.

#attribute_for_inspect

Returns an #inspect-like string for the value of the attribute attr_name.

#attribute_names

Returns an array of names for the attributes available on this object.

#attribute_present?

Returns true if the specified attribute has been set by the user or by a database load and is neither nil nor empty? (the latter only applies to objects that respond to empty?, most notably Strings).

#attributes

Returns a hash of all the attributes with their names as keys and the values of the attributes as values.

#has_attribute?

Returns true if the given attribute is in the attributes hash, otherwise false.

#respond_to?

A Person object with a name attribute can ask person.respond_to?(:name), person.respond_to?(:name=), and person.respond_to?(:name?) which will all return true.

::ActiveModel::AttributeMethods - Included

#attribute_missing

attribute_missing is like method_missing, but for attributes.

#method_missing

Allows access to the object attributes, which are held in the hash returned by attributes, as though they were first-class methods.

#respond_to?,
#respond_to_without_attributes?

A Person instance with a name attribute can ask person.respond_to?(:name), person.respond_to?(:name=), and person.respond_to?(:name?) which will all return true.

Locking::Pessimistic - Included

#lock!

Obtain a row lock on this record.

#with_lock

Wraps the passed block in a transaction, locking the object before yielding.

Validations - Included

#save

The validation process on save can be skipped by passing validate: false.

#save!

Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false if the record is not valid.

#valid?

Runs all the validations within the specified context.

#validate
#validate!

Runs all the validations within the specified context.

::ActiveModel::Validations::HelperMethods - Included

#validates_absence_of

Validates that the specified attributes are blank (as defined by Object#blank?).

#validates_acceptance_of

Encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement).

#validates_confirmation_of

Encapsulates the pattern of wanting to validate a password or email address field with a confirmation.

#validates_exclusion_of

Validates that the value of the specified attribute is not in a particular enumerable object.

#validates_format_of

Validates whether the value of the specified attribute is of the correct form, going by the regular expression provided.

#validates_inclusion_of

Validates whether the value of the specified attribute is available in a particular enumerable object.

#validates_length_of

Validates that the specified attribute matches the length restrictions supplied.

#validates_numericality_of

Validates whether the value of the specified attribute is numeric by trying to convert it to a float with Kernel.Float (if only_integer is false) or applying it to the regular expression /\A[+\-]?\d+\Z/ (if only_integer is set to true).

#validates_presence_of

Validates that the specified attributes are not blank (as defined by Object#blank?).

#validates_size_of

::ActiveModel::Validations - Included

#errors

Returns the Errors object that holds all information about attribute error messages.

#invalid?

Performs the opposite of valid?.

#read_attribute_for_validation

Hook method defining how an attribute value should be retrieved.

#valid?

Runs all the specified validations and returns true if no errors were added otherwise false.

#validate
#validates_with

Passes the record off to the class or classes specified and allows them to add errors based on more complex conditions.

Integration - Included

#cache_key

Returns a cache key that can be used to identify this record.

#to_param

Returns a ::String, which Action Pack uses for constructing an URL to this object.

::ActiveModel::Conversion - Included

#to_key

Returns an ::Array of all key attributes if any is set, regardless if the object is persisted or not.

#to_model

If your object is already designed to implement all of the Active Model you can use the default :to_model implementation, which simply returns self.

#to_param

Returns a string representing the object's key suitable for use in URLs, or nil if persisted? is false.

#to_partial_path

Returns a string identifying the path associated with the object.

AttributeAssignment - Included

#assign_attributes

Allows you to set all the attributes by passing in a hash of attributes with keys matching the attribute names (which again matches the column names).

Sanitization - Included

#quoted_id

TODO: Deprecate this.

Scoping - Included

Inheritance - Included

Persistence - Included

#becomes

Returns an instance of the specified klass with the attributes of the current record.

#becomes!

Wrapper around becomes that also changes the instance's sti column value.

#decrement

Initializes attribute to zero if nil and subtracts the value passed as by (default is 1).

#decrement!

Wrapper around decrement that saves the record.

#delete

Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted).

#destroy

Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted).

#destroy!

Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted).

#increment

Initializes attribute to zero if nil and adds the value passed as by (default is 1).

#increment!

Wrapper around increment that saves the record.

#reload

Reloads the record from the database.

#save

Saves the model.

#save!

Saves the model.

#toggle

Assigns to attribute the boolean opposite of attribute?.

#toggle!

Wrapper around toggle that saves the record.

#touch

Saves the record with the updated_at/on attributes set to the current time.

#update

Updates the attributes of the model from the passed-in hash and saves the record, all wrapped in a transaction.

#update!

Updates its receiver just like update but calls save! instead of save, so an exception is raised if the record is invalid.

#update_attribute

Updates a single attribute and saves the record.

#update_attributes
#update_attributes!
#update_column

Equivalent to update_columns(name => value).

#update_columns

Updates the attributes directly in the database issuing an UPDATE SQL statement and sets them in the receiver:

Core - Included

#<=>

Allows sort on objects.

#==

Returns true if comparison_object is the same exact object, or comparison_object is of the same type and self has an ID and it is equal to comparison_object.id.

#clone

Identical to Ruby's clone method.

#connection_handler,
#dup

Duped objects have no id assigned and are treated as new records.

#encode_with

Populate coder with attributes about this record that should be serialized.

#eql?

Alias for Core#==.

#freeze

Clone and freeze the attributes hash such that associations are still accessible, even on destroyed records, but cloned models will not be frozen.

#hash

Delegates to id in order to allow two records of the same type and id to work with something like:

#init_with

Initialize an empty model object from coder.

#initialize

New objects can be instantiated as either empty (pass no construction parameter) or pre-set with attributes but not yet saved (pass a hash with key names matching the associated table column names).

#inspect

Returns the contents of the record as a nicely formatted string.

#pretty_print

Takes a PP and prettily prints this record to it, allowing you to get a nice result from pp record when pp is required.

#readonly!

Marks this record as read only.

#slice

Returns a hash of the given methods with their names as keys and returned values as values.

Dynamic Method Handling

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

Class Attribute Details

.table_exists?Boolean (readonly)

[ GitHub ]

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

def table_exists?
  connection.table_exists?(table_name)
end

Class Method Details

.create_table(limit = nil)

[ GitHub ]

  
# 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_table

[ GitHub ]

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

def drop_table
  connection.drop_table table_name if table_exists?
end

.index_name

[ GitHub ]

  
# 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)

[ GitHub ]

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

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

.normalized_versions

[ GitHub ]

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

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

.primary_key

[ GitHub ]

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

def primary_key
  nil
end

.table_name

[ GitHub ]

  
# 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

#version

[ GitHub ]

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

def version
  super.to_i
end