Class: ActiveRecord::Migrator
- Inherits:
-
Object
- Object
- ActiveRecord::Migrator
- Defined in:
- lib/active_record/migration.rb
Class Method Summary collapse
- .current_version ⇒ Object
- .down(migrations_path, target_version = nil) ⇒ Object
- .up(migrations_path, target_version = nil) ⇒ Object
Instance Method Summary collapse
- #current_version ⇒ Object
-
#initialize(direction, migrations_path, target_version = nil) ⇒ Migrator
constructor
A new instance of Migrator.
- #migrate ⇒ Object
Constructor Details
#initialize(direction, migrations_path, target_version = nil) ⇒ Migrator
32 33 34 35 |
# File 'lib/active_record/migration.rb', line 32 def initialize(direction, migrations_path, target_version = nil) @direction, @migrations_path, @target_version = direction, migrations_path, target_version Base.connection.initialize_schema_information end |
Class Method Details
.current_version ⇒ Object
27 28 29 |
# File 'lib/active_record/migration.rb', line 27 def current_version Base.connection.select_one("SELECT version FROM schema_info")["version"].to_i end |
.down(migrations_path, target_version = nil) ⇒ Object
23 24 25 |
# File 'lib/active_record/migration.rb', line 23 def down(migrations_path, target_version = nil) new(:down, migrations_path, target_version).migrate end |
.up(migrations_path, target_version = nil) ⇒ Object
19 20 21 |
# File 'lib/active_record/migration.rb', line 19 def up(migrations_path, target_version = nil) new(:up, migrations_path, target_version).migrate end |
Instance Method Details
#current_version ⇒ Object
37 38 39 |
# File 'lib/active_record/migration.rb', line 37 def current_version self.class.current_version end |
#migrate ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_record/migration.rb', line 41 def migrate migration_classes do |version, migration_class| Base.logger.info("Reached target version: #{@target_version}") and break if reached_target_version?(version) next if irrelevant_migration?(version) Base.logger.info "Migrating to #{migration_class} (#{version})" migration_class.send(@direction) set_schema_version(version) end end |