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, 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.
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 |
# File 'lib/active_record/migration.rb', line 1421 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.
1407 1408 1409 |
# File 'lib/active_record/migration.rb', line 1407 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
1410 1411 1412 1413 1414 1415 1416 |
# File 'lib/active_record/migration.rb', line 1410 def current_version connection_pool = ActiveRecord::Tasks::DatabaseTasks.migration_connection_pool schema_migration = SchemaMigration.new(connection_pool) = InternalMetadata.new(connection_pool) MigrationContext.new(migrations_paths, schema_migration, ).current_version end |
Instance Method Details
#current_migration ⇒ Object Also known as: current
1439 1440 1441 |
# File 'lib/active_record/migration.rb', line 1439 def current_migration migrations.detect { |m| m.version == current_version } end |
#current_version ⇒ Object
1435 1436 1437 |
# File 'lib/active_record/migration.rb', line 1435 def current_version migrated.max || 0 end |
#load_migrated ⇒ Object
1484 1485 1486 |
# File 'lib/active_record/migration.rb', line 1484 def load_migrated @migrated_versions = Set.new(@schema_migration.integer_versions) end |
#migrate ⇒ Object
1452 1453 1454 1455 1456 1457 1458 |
# File 'lib/active_record/migration.rb', line 1452 def migrate if use_advisory_lock? with_advisory_lock { migrate_without_lock } else migrate_without_lock end end |
#migrated ⇒ Object
1480 1481 1482 |
# File 'lib/active_record/migration.rb', line 1480 def migrated @migrated_versions || load_migrated end |
#migrations ⇒ Object
1471 1472 1473 |
# File 'lib/active_record/migration.rb', line 1471 def migrations down? ? @migrations.reverse : @migrations.sort_by(&:version) end |
#pending_migrations ⇒ Object
1475 1476 1477 1478 |
# File 'lib/active_record/migration.rb', line 1475 def pending_migrations already_migrated = migrated migrations.reject { |m| already_migrated.include?(m.version) } end |
#run ⇒ Object
1444 1445 1446 1447 1448 1449 1450 |
# File 'lib/active_record/migration.rb', line 1444 def run if use_advisory_lock? with_advisory_lock { run_without_lock } else run_without_lock end end |
#runnable ⇒ Object
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 |
# File 'lib/active_record/migration.rb', line 1460 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 |