0
0
Ruby on Railsframework~20 mins

Running and rolling back migrations in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Migration Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens after running rails db:migrate?
You run rails db:migrate in your Rails project. What is the immediate effect on your database?
AAll migrations are deleted from the migrations folder to prevent rerunning.
BThe database is reset to its initial empty state, removing all tables.
CThe Rails server automatically restarts to apply migration changes.
DThe database schema is updated to include all pending migrations, and a record is added to the schema_migrations table.
Attempts:
2 left
💡 Hint
Think about what migrations do to the database structure and how Rails tracks them.
state_output
intermediate
2:00remaining
What is the state of the database after rails db:rollback?
After running rails db:migrate to apply three migrations, you run rails db:rollback. What is the state of the database schema?
AThe last applied migration is reversed, so the database schema reflects only the first two migrations.
BAll migrations are reversed, and the database schema is empty.
CThe database schema remains unchanged because rollback only affects migration files.
DThe first migration is reversed, but the last two remain applied.
Attempts:
2 left
💡 Hint
Rollback undoes migrations one step at a time, starting from the most recent.
📝 Syntax
advanced
2:00remaining
Which command rolls back the last two migrations?
You want to undo the last two migrations you applied. Which command correctly does this?
Arails db:migrate:down VERSION=2
Brails db:rollback --count=2
Crails db:rollback STEP=2
Drails db:reset STEP=2
Attempts:
2 left
💡 Hint
Look for the option that specifies how many steps to rollback.
🔧 Debug
advanced
2:00remaining
Why does rails db:rollback fail with 'No migrations to rollback'?
You run rails db:rollback but get the error 'No migrations to rollback'. What is the most likely reason?
AThere are no migrations applied yet, so nothing to rollback.
BThe migration files are missing from the project folder.
CThe database connection is not established.
DThe Rails version does not support rollback commands.
Attempts:
2 left
💡 Hint
Rollback only works if migrations have been applied before.
🧠 Conceptual
expert
3:00remaining
What is the effect of rails db:migrate:redo?
You run rails db:migrate:redo. What does this command do to your database schema?
AIt deletes the last migration file and updates the schema accordingly.
BIt rolls back the last migration and then reapplies it, effectively refreshing the last migration.
CIt applies all pending migrations without rolling back any.
DIt resets the entire database and reapplies all migrations from scratch.
Attempts:
2 left
💡 Hint
Think about what 'redo' means in terms of undoing and reapplying.