Class: ActiveRecord::Migrator
- Inherits:
-
Object
- Object
- ActiveRecord::Migrator
- Defined in:
- lib/active_record/migration.rb
Overview
:nodoc:
Class Attribute Summary collapse
-
.migrations_paths ⇒ Object
Returns the value of attribute migrations_paths.
Class Method Summary collapse
-
.current_version ⇒ Object
For cases where a table doesn’t exist like loading from schema cache.
Instance Method Summary collapse
- #current_migration ⇒ Object (also: #current)
- #current_version ⇒ Object
-
#initialize(direction, migrations, schema_migration, target_version = nil) ⇒ Migrator
constructor
A new instance of Migrator.
- #load_migrated ⇒ Object
- #migrate ⇒ Object
- #migrated ⇒ Object
- #migrations ⇒ Object
- #pending_migrations ⇒ Object
- #run ⇒ Object
- #runnable ⇒ Object
Constructor Details
#initialize(direction, migrations, schema_migration, target_version = nil) ⇒ Migrator
Returns a new instance of Migrator.
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 |
# File 'lib/active_record/migration.rb', line 1197 def initialize(direction, migrations, schema_migration, target_version = nil) @direction = direction @target_version = target_version @migrated_versions = nil @migrations = migrations @schema_migration = schema_migration validate(@migrations) @schema_migration.create_table ActiveRecord::InternalMetadata.create_table end |
Class Attribute Details
.migrations_paths ⇒ Object
Returns the value of attribute migrations_paths.
1187 1188 1189 |
# File 'lib/active_record/migration.rb', line 1187 def migrations_paths @migrations_paths end |
Class Method Details
.current_version ⇒ Object
For cases where a table doesn’t exist like loading from schema cache
1190 1191 1192 |
# File 'lib/active_record/migration.rb', line 1190 def current_version MigrationContext.new(migrations_paths, SchemaMigration).current_version end |
Instance Method Details
#current_migration ⇒ Object Also known as: current
1214 1215 1216 |
# File 'lib/active_record/migration.rb', line 1214 def current_migration migrations.detect { |m| m.version == current_version } end |
#current_version ⇒ Object
1210 1211 1212 |
# File 'lib/active_record/migration.rb', line 1210 def current_version migrated.max || 0 end |
#load_migrated ⇒ Object
1259 1260 1261 |
# File 'lib/active_record/migration.rb', line 1259 def load_migrated @migrated_versions = Set.new(@schema_migration.all_versions.map(&:to_i)) end |
#migrate ⇒ Object
1227 1228 1229 1230 1231 1232 1233 |
# File 'lib/active_record/migration.rb', line 1227 def migrate if use_advisory_lock? with_advisory_lock { migrate_without_lock } else migrate_without_lock end end |
#migrated ⇒ Object
1255 1256 1257 |
# File 'lib/active_record/migration.rb', line 1255 def migrated @migrated_versions || load_migrated end |
#migrations ⇒ Object
1246 1247 1248 |
# File 'lib/active_record/migration.rb', line 1246 def migrations down? ? @migrations.reverse : @migrations.sort_by(&:version) end |
#pending_migrations ⇒ Object
1250 1251 1252 1253 |
# File 'lib/active_record/migration.rb', line 1250 def pending_migrations already_migrated = migrated migrations.reject { |m| already_migrated.include?(m.version) } end |
#run ⇒ Object
1219 1220 1221 1222 1223 1224 1225 |
# File 'lib/active_record/migration.rb', line 1219 def run if use_advisory_lock? with_advisory_lock { run_without_lock } else run_without_lock end end |
#runnable ⇒ Object
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 |
# File 'lib/active_record/migration.rb', line 1235 def runnable runnable = migrations[start..finish] if up? runnable.reject { |m| ran?(m) } else # skip the last migration if we're headed down, but not ALL the way down runnable.pop if target runnable.find_all { |m| ran?(m) } end end |