Class: ActiveRecord::Migrator
- Defined in:
- activerecord/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, internal_metadata, 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, internal_metadata, target_version = nil) ⇒ Migrator
Returns a new instance of Migrator.
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 |
# File 'activerecord/lib/active_record/migration.rb', line 1335 def initialize(direction, migrations, schema_migration, , target_version = nil) @direction = direction @target_version = target_version @migrated_versions = nil @migrations = migrations @schema_migration = schema_migration @internal_metadata = validate(@migrations) @schema_migration.create_table @internal_metadata.create_table end |
Class Attribute Details
.migrations_paths ⇒ Object
Returns the value of attribute migrations_paths
1321 1322 1323 |
# File 'activerecord/lib/active_record/migration.rb', line 1321 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
1324 1325 1326 1327 1328 1329 1330 |
# File 'activerecord/lib/active_record/migration.rb', line 1324 def current_version connection = ActiveRecord::Tasks::DatabaseTasks.migration_connection schema_migration = SchemaMigration.new(connection) = InternalMetadata.new(connection) MigrationContext.new(migrations_paths, schema_migration, ).current_version end |
Instance Method Details
#current_migration ⇒ Object Also known as: current
1353 1354 1355 |
# File 'activerecord/lib/active_record/migration.rb', line 1353 def current_migration migrations.detect { |m| m.version == current_version } end |
#current_version ⇒ Object
1349 1350 1351 |
# File 'activerecord/lib/active_record/migration.rb', line 1349 def current_version migrated.max || 0 end |
#load_migrated ⇒ Object
1398 1399 1400 |
# File 'activerecord/lib/active_record/migration.rb', line 1398 def load_migrated @migrated_versions = Set.new(@schema_migration.integer_versions) end |
#migrate ⇒ Object
1366 1367 1368 1369 1370 1371 1372 |
# File 'activerecord/lib/active_record/migration.rb', line 1366 def migrate if use_advisory_lock? with_advisory_lock { migrate_without_lock } else migrate_without_lock end end |
#migrated ⇒ Object
1394 1395 1396 |
# File 'activerecord/lib/active_record/migration.rb', line 1394 def migrated @migrated_versions || load_migrated end |
#migrations ⇒ Object
1385 1386 1387 |
# File 'activerecord/lib/active_record/migration.rb', line 1385 def migrations down? ? @migrations.reverse : @migrations.sort_by(&:version) end |
#pending_migrations ⇒ Object
1389 1390 1391 1392 |
# File 'activerecord/lib/active_record/migration.rb', line 1389 def pending_migrations already_migrated = migrated migrations.reject { |m| already_migrated.include?(m.version) } end |
#run ⇒ Object
1358 1359 1360 1361 1362 1363 1364 |
# File 'activerecord/lib/active_record/migration.rb', line 1358 def run if use_advisory_lock? with_advisory_lock { run_without_lock } else run_without_lock end end |
#runnable ⇒ Object
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 |
# File 'activerecord/lib/active_record/migration.rb', line 1374 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 |