ActiveRecord.Migrator class
Part of Active Record
Runs a list of migrations in one direction. A migrator is created by
ActiveRecord::MigrationContext with the direction ('up' or 'down'), the migrations
that exist and an optional target version. It works out which of them have to run by
comparing them with the versions stored by ActiveRecord::SchemaMigration, and runs
each one inside of a transaction if the database supports it, storing or forgetting its
version afterward. A migration that fails is rolled back and cancels the ones after it.
This file also loads the other parts of the migrations system.
Summary
Methods
Methods
ActiveRecord.Migrator:current_migration()
shared packages/active_record/lib/migrator/migrator.lua:87Returns the migration of the newest version that has been run.
Returns
- ActiveRecord::MigrationProxy or nil
Returns the newest version that has been run.
Returns
- Number 0 if no migration has been run
Checks whether the migrator migrates down.
Returns
- Boolean
ActiveRecord.Migrator:execute_migration_in_transaction(migration)
shared packages/active_record/lib/migrator/migrator.lua:214Runs a migration in the direction of the migrator, inside of a transaction if the database supports it. Records the version as run (or forgets it) afterward. A failed migration is rolled back and raises an error, so that no later migration runs. Foreign keys are not enforced while the migration runs on a database that rebuilds tables to change them, as SQLite does; they are checked before the migration is committed, and a row that the migration has made break one fails it.
Parameters
- migration ActiveRecord::MigrationProxy
Returns
- Boolean whether the migration was run; false if it had been run (or reverted) already
ActiveRecord.Migrator:init(direction, migrations, target_version)
shared packages/active_record/lib/migrator/migrator.lua:26Creates a migrator, which runs a list of migrations in one direction. Normally created by ActiveRecord::MigrationContext.
Parameters
- direction String 'up' or 'down'
- migrations List<ActiveRecord::MigrationProxy> sorted by version
- target_version Number optional, defaults to
nilversion to migrate to
Returns
- ActiveRecord::Migrator(self)
Checks whether a target version was given that no migration has.
Returns
- Boolean
Runs every runnable migration.
Returns
- List<ActiveRecord::MigrationProxy> migrations that were run
Returns the versions of the migrations that have been run, as a set.
Returns
- Map version to true
ActiveRecord.Migrator:pending_migrations()
shared packages/active_record/lib/migrator/migrator.lua:113Returns the migrations that have not been run yet, oldest first.
Returns
- List<ActiveRecord::MigrationProxy>
Checks whether a migration has been run.
Parameters
- migration ActiveRecord::MigrationProxy
Returns
- Boolean
ActiveRecord.Migrator:record_version_state_after_migrating(version)
shared packages/active_record/lib/migrator/migrator.lua:286Records that a migration was run, or that it was reverted.
Parameters
- version Number
Runs only the migration of the target version.
Returns
- List<ActiveRecord::MigrationProxy> the migration, if it was run
Returns the migrations that #migrate runs: going up, the pending migrations up to the target; going down, the migrations that have been run, from the current one down to (but not including) the target.
Returns
- List<ActiveRecord::MigrationProxy>
Returns the migration of the target version.
Returns
- ActiveRecord::MigrationProxy or nil
Checks whether the migrator migrates up.
Returns
- Boolean