Permalink
Browse files

Add additional raise UnknownMigrationVersionError

Raise error on the movement of migrations
when the current migration does not exist.
  • Loading branch information...
bogdanvlviv committed Feb 25, 2017
1 parent b77d2aa commit bb9d6eb094f29bb94ef1f26aa44f145f17b973fe
@@ -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*
@@ -1105,18 +1105,20 @@ def migration_files(paths)
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
else
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
@@ -167,6 +167,37 @@ class AMigration < ActiveRecord::Migration::Current
end
end
test "raise error on any move when current migration does not exist" do
Dir.chdir(app_path) do
`bin/rails generate model user username:string password:string;
bin/rails generate migration add_email_to_users email:string;
bin/rails db:migrate
rm db/migrate/*email*.rb`
output = `bin/rails db:migrate:status`
assert_match(/up\s+\d{14}\s+Create users/, output)
assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)
output = `bin/rails db:rollback 2>&1`
assert_match(/rails aborted!/, output)
assert_match(/ActiveRecord::UnknownMigrationVersionError:/, output)
assert_match(/No migration with version number\s\d{14}\./, output)
output = `bin/rails db:migrate:status`
assert_match(/up\s+\d{14}\s+Create users/, output)
assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)
output = `bin/rails db:forward 2>&1`
assert_match(/rails aborted!/, output)
assert_match(/ActiveRecord::UnknownMigrationVersionError:/, output)
assert_match(/No migration with version number\s\d{14}\./, output)
output = `bin/rails db:migrate:status`
assert_match(/up\s+\d{14}\s+Create users/, output)
assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)
end
end
test "migration status after rollback and redo without timestamps" do
add_to_config("config.active_record.timestamped_migrations = false")
@@ -257,7 +288,6 @@ class TwoMigration < ActiveRecord::Migration::Current
rm db/migrate/*email*.rb`
output = `bin/rails db:migrate:status`
File.write("test.txt", output)
assert_match(/up\s+\d{14}\s+Create users/, output)
assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)

0 comments on commit bb9d6eb

Please sign in to comment.