Challenge - 5 Problems
Migration Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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?Attempts:
2 left
💡 Hint
Think about what migrations do to the database structure and how Rails tracks them.
✗ Incorrect
Running rails db:migrate applies all pending migrations to update the database schema. Rails records which migrations have run in the schema_migrations table to avoid rerunning them.
❓ state_output
intermediate2: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?Attempts:
2 left
💡 Hint
Rollback undoes migrations one step at a time, starting from the most recent.
✗ Incorrect
rails db:rollback reverses the last migration that was applied, updating the database schema accordingly. It does not undo all migrations at once.
📝 Syntax
advanced2:00remaining
Which command rolls back the last two migrations?
You want to undo the last two migrations you applied. Which command correctly does this?
Attempts:
2 left
💡 Hint
Look for the option that specifies how many steps to rollback.
✗ Incorrect
The STEP option tells Rails how many migrations to rollback. rails db:rollback STEP=2 rolls back the last two migrations.
🔧 Debug
advanced2: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?Attempts:
2 left
💡 Hint
Rollback only works if migrations have been applied before.
✗ Incorrect
If no migrations have been applied, Rails cannot rollback anything and shows this error.
🧠 Conceptual
expert3: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?Attempts:
2 left
💡 Hint
Think about what 'redo' means in terms of undoing and reapplying.
✗ Incorrect
rails db:migrate:redo rolls back the last migration and then runs it again. This is useful for testing or fixing the last migration.