Class: ActiveRecord::SchemaMigration
- Defined in:
- lib/active_record/schema_migration.rb
Overview
This class is used to create a table that keeps track of which migrations have been applied to a given database. When a migration is run, its schema number is inserted in to the ‘SchemaMigration.table_name` so it doesn’t need to be executed the next time.
Constant Summary
Constants included from ConnectionHandling
ConnectionHandling::DEFAULT_ENV, ConnectionHandling::RAILS_ENV
Constants included from Transactions
Constants included from Callbacks
Constants included from AttributeMethods
AttributeMethods::AttrNames, AttributeMethods::BLACKLISTED_CLASS_METHODS
Instance Attribute Summary
Attributes included from ConnectionHandling
#connection_specification_name
Class Method Summary collapse
- .all_versions ⇒ Object
- .create_table ⇒ Object
- .drop_table ⇒ Object
- .normalize_migration_number(number) ⇒ Object
- .normalized_versions ⇒ Object
- .primary_key ⇒ Object
- .table_exists? ⇒ Boolean
- .table_name ⇒ Object
Instance Method Summary collapse
Methods included from ConnectionHandling
#clear_cache!, #connected?, #connection, #connection_config, #connection_pool, #establish_connection, #mysql2_connection, #postgresql_connection, #remove_connection, #retrieve_connection, #sqlite3_connection
Methods included from QueryCache::ClassMethods
Methods included from Querying
Methods included from Translation
#i18n_scope, #lookup_ancestors
Methods included from DynamicMatchers
Methods included from Explain
#collecting_queries_for_explain, #exec_explain
Methods included from Enum
Methods included from Delegation::DelegateCache
#inherited, #initialize_relation_delegate_cache, #relation_delegate_class
Methods included from CollectionCacheKey
Methods included from Suppressor
Methods included from Serialization
Methods included from Reflection
add_aggregate_reflection, add_reflection, create
Methods included from NoTouching
applied_to?, apply_to, #no_touching?, #touch, #touch_later
Methods included from TouchLater
Methods included from Transactions
#add_to_transaction, #before_committed!, #committed!, #destroy, #rollback_active_record_state!, #rolledback!, #save, #save!, #touch, #transaction, #with_transaction_returning_status
Methods included from Aggregations
Methods included from NestedAttributes
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, #association_cached?, eager_load!, #initialize_dup, #reload
Methods included from Timestamp
Methods included from Callbacks
Methods included from AttributeMethods
#[], #[]=, #accessed_fields, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #has_attribute?, #respond_to?
Methods included from Locking::Pessimistic
Methods included from Locking::Optimistic
Methods included from Validations
Methods included from Integration
Methods included from AttributeAssignment
Methods included from Sanitization
Methods included from Scoping
#initialize_internals_callback, #populate_with_current_scope_attributes
Methods included from Inheritance
Methods included from ModelSchema
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
Class Method Details
.all_versions ⇒ Object
45 46 47 |
# File 'lib/active_record/schema_migration.rb', line 45 def all_versions order(:version).pluck(:version) end |
.create_table ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record/schema_migration.rb', line 23 def create_table unless table_exists? = connection. connection.create_table(table_name, id: false) do |t| t.string :version, end end end |
.drop_table ⇒ Object
33 34 35 |
# File 'lib/active_record/schema_migration.rb', line 33 def drop_table connection.drop_table table_name, if_exists: true end |
.normalize_migration_number(number) ⇒ Object
37 38 39 |
# File 'lib/active_record/schema_migration.rb', line 37 def normalize_migration_number(number) "%.3d" % number.to_i end |
.normalized_versions ⇒ Object
41 42 43 |
# File 'lib/active_record/schema_migration.rb', line 41 def normalized_versions all_versions.map { |v| normalize_migration_number v } end |
.primary_key ⇒ Object
11 12 13 |
# File 'lib/active_record/schema_migration.rb', line 11 def primary_key "version" end |
.table_exists? ⇒ Boolean
19 20 21 |
# File 'lib/active_record/schema_migration.rb', line 19 def table_exists? connection.table_exists?(table_name) end |
.table_name ⇒ Object
15 16 17 |
# File 'lib/active_record/schema_migration.rb', line 15 def table_name "#{table_name_prefix}#{ActiveRecord::Base.schema_migrations_table_name}#{table_name_suffix}" end |
Instance Method Details
#version ⇒ Object
50 51 52 |
# File 'lib/active_record/schema_migration.rb', line 50 def version super.to_i end |