Skip to content

Commit

Permalink
Fix bin/rails db:forward first migration
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanvlviv committed Apr 19, 2017
1 parent c324f5d commit b77d2aa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
* Fix `bin/rails db:forward` first migration.

*bogdanvlviv*

* Support Descending Indexes for MySQL. * Support Descending Indexes for MySQL.


MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored. MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
Expand Down
8 changes: 7 additions & 1 deletion activerecord/lib/active_record/migration.rb
Expand Up @@ -1104,7 +1104,13 @@ def migration_files(paths)


def move(direction, migrations_paths, steps) def move(direction, migrations_paths, steps)
migrator = new(direction, migrations(migrations_paths)) migrator = new(direction, migrations(migrations_paths))
start_index = migrator.migrations.index(migrator.current_migration)
start_index =
if current_version == 0
0
else
migrator.migrations.index(migrator.current_migration)
end


if start_index if start_index
finish = migrator.migrations[start_index + steps] finish = migrator.migrations[start_index + steps]
Expand Down
25 changes: 25 additions & 0 deletions railties/test/application/rake/migrations_test.rb
Expand Up @@ -142,6 +142,31 @@ class AMigration < ActiveRecord::Migration::Current
end end
end end


test "migration status after rollback and forward" 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`

output = `bin/rails db:migrate:status`

assert_match(/up\s+\d{14}\s+Create users/, output)
assert_match(/up\s+\d{14}\s+Add email to users/, output)

`bin/rails db:rollback STEP=2`
output = `bin/rails db:migrate:status`

assert_match(/down\s+\d{14}\s+Create users/, output)
assert_match(/down\s+\d{14}\s+Add email to users/, output)

`bin/rails db:forward STEP=2`
output = `bin/rails db:migrate:status`

assert_match(/up\s+\d{14}\s+Create users/, output)
assert_match(/up\s+\d{14}\s+Add email to users/, output)
end
end

test "migration status after rollback and redo without timestamps" do test "migration status after rollback and redo without timestamps" do
add_to_config("config.active_record.timestamped_migrations = false") add_to_config("config.active_record.timestamped_migrations = false")


Expand Down

0 comments on commit b77d2aa

Please sign in to comment.