From bb9d6eb094f29bb94ef1f26aa44f145f17b973fe Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Sat, 25 Feb 2017 19:32:50 +0200 Subject: Add additional raise UnknownMigrationVersionError Raise error on the movement of migrations when the current migration does not exist. --- activerecord/CHANGELOG.md | 5 +++++ activerecord/lib/active_record/migration.rb | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index d8f93280cd..f0cfd0469e 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Raise error `UnknownMigrationVersionError` on the movement of migrations + when the current migration does not exist. + + *bogdanvlviv* + * Fix `bin/rails db:forward` first migration. *bogdanvlviv* diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 43b6a746e0..51c82f4ced 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -1105,6 +1105,10 @@ module ActiveRecord def move(direction, migrations_paths, steps) migrator = new(direction, migrations(migrations_paths)) + if current_version != 0 && !migrator.current_migration + raise UnknownMigrationVersionError.new(current_version) + end + start_index = if current_version == 0 0 @@ -1112,11 +1116,9 @@ module ActiveRecord migrator.migrations.index(migrator.current_migration) end - if start_index - finish = migrator.migrations[start_index + steps] - version = finish ? finish.version : 0 - send(direction, migrations_paths, version) - end + finish = migrator.migrations[start_index + steps] + version = finish ? finish.version : 0 + send(direction, migrations_paths, version) end end -- cgit v1.2.3