MigrationContext sets the context in which a migration is run.
A migration context requires the path to the migrations is set in the
migrations_paths parameter. Optionally a
schema_migration class can be provided. For most applications,
SchemaMigration is sufficient. Multiple database applications need a
SchemaMigration per primary database.
# File activerecord/lib/active_record/migration.rb, line 1070 def initialize(migrations_paths, schema_migration = SchemaMigration) @migrations_paths = migrations_paths @schema_migration = schema_migration end
# File activerecord/lib/active_record/migration.rb, line 1088 def migrate(target_version = nil, &block) case when target_version.nil? up(target_version, &block) when current_version == 0 && target_version == 0  when current_version > target_version down(target_version, &block) else up(target_version, &block) end end
Runs the migrations in the
migrate will run
target_version are both 0 then an empty array will be returned and no migrations will be run.
current_version in the schema is greater than the
down will be run.
If none of the conditions are met,
up will be run with the
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.