Bird
0
0

Why is it important to write both up() and down() methods in a migration?

hard📝 Conceptual Q10 of 15
NestJS - Database with TypeORM
Why is it important to write both up() and down() methods in a migration?
ATo handle user authentication during migration
BTo apply and revert database schema changes safely
CTo generate API endpoints automatically
DTo speed up migration execution time
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of up() and down()

    up() applies schema changes; down() reverts them to previous state.
  2. Step 2: Recognize importance for safety

    Having both methods allows safe rollback if needed, preventing data loss or errors.
  3. Final Answer:

    To apply and revert database schema changes safely -> Option B
  4. Quick Check:

    up/down methods = apply and revert changes [OK]
Quick Trick: Write up() and down() to apply and undo changes [OK]
Common Mistakes:
  • Thinking down() speeds up migrations
  • Assuming migrations generate API endpoints
  • Confusing migrations with authentication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes