Class: ActiveRecord::Migrator
- Inherits:
-
Object
- Object
- ActiveRecord::Migrator
- Defined in:
- lib/active_record/migration.rb
Overview
:nodoc:
Class Method Summary collapse
- .current_version ⇒ Object
- .down(migrations_path, target_version = nil) ⇒ Object
- .migrate(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
Returns a new instance of Migrator.
161 162 163 164 165 |
# File 'lib/active_record/migration.rb', line 161 def initialize(direction, migrations_path, target_version = nil) raise StandardError.new("This database does not yet support migrations") unless Base.connection.supports_migrations? @direction, @migrations_path, @target_version = direction, migrations_path, target_version Base.connection.initialize_schema_information end |
Class Method Details
.current_version ⇒ Object
156 157 158 |
# File 'lib/active_record/migration.rb', line 156 def current_version Base.connection.select_one("SELECT version FROM schema_info")["version"].to_i end |
.down(migrations_path, target_version = nil) ⇒ Object
152 153 154 |
# File 'lib/active_record/migration.rb', line 152 def down(migrations_path, target_version = nil) self.new(:down, migrations_path, target_version).migrate end |
.migrate(migrations_path, target_version = nil) ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/active_record/migration.rb', line 137 def migrate(migrations_path, target_version = nil) case when target_version.nil?, current_version < target_version up(migrations_path, target_version) when current_version > target_version down(migrations_path, target_version) when current_version == target_version return # You're on the right version end end |
.up(migrations_path, target_version = nil) ⇒ Object
148 149 150 |
# File 'lib/active_record/migration.rb', line 148 def up(migrations_path, target_version = nil) self.new(:up, migrations_path, target_version).migrate end |
Instance Method Details
#current_version ⇒ Object
167 168 169 |
# File 'lib/active_record/migration.rb', line 167 def current_version self.class.current_version end |
#migrate ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/active_record/migration.rb', line 171 def migrate migration_classes.each 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 |