Bird
Raised Fist0
Supabasecloud~20 mins

Rolling back migrations in Supabase - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Supabase Migration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
What happens when you run a rollback migration in Supabase?

In Supabase, you apply migrations to update your database schema. What is the result of running a rollback migration?

AThe migration is applied again, adding new tables and columns.
BThe database schema deletes all tables and data permanently.
CThe database schema reverts to the previous state before the last migration was applied.
DThe database connection is reset but schema remains unchanged.
Attempts:
2 left
💡 Hint

Think about what rollback means in the context of database changes.

❓ Configuration
intermediate
2:00remaining
Which command correctly rolls back the last migration in Supabase CLI?

You want to undo the last migration applied to your Supabase database using the CLI. Which command should you use?

Asupabase db revert
Bsupabase db rollback
Csupabase db migrate undo
Dsupabase migration down
Attempts:
2 left
💡 Hint

Check the official Supabase CLI commands for migration rollback.

❓ Architecture
advanced
3:00remaining
What is the best practice to ensure safe rollback of migrations in a production Supabase database?

When managing migrations in production, what practice helps ensure that rolling back a migration does not cause data loss or downtime?

AAvoid using migrations and manually change the schema in production.
BDelete the production database and restore from backup after rollback.
CApply rollbacks directly in production without testing to save time.
DAlways write reversible migrations with explicit down scripts and test them in staging before production.
Attempts:
2 left
💡 Hint

Think about how to avoid surprises when undoing database changes.

❓ security
advanced
3:00remaining
Which security risk is most relevant when rolling back migrations in Supabase?

Rolling back migrations can affect database security. What is a key security risk to consider?

ARollback might remove security policies or roles, exposing data unintentionally.
BRollback encrypts all data, making it inaccessible.
CRollback disables all user authentication temporarily.
DRollback automatically grants admin rights to all users.
Attempts:
2 left
💡 Hint

Consider what schema elements control access and how rollback affects them.

🧠 Conceptual
expert
3:00remaining
After rolling back a migration that dropped a column, what happens to the data in that column in Supabase?

You rolled back a migration that previously dropped a column from a table. What is the state of the data that was in that column?

AThe column is restored but all previous data in it is lost permanently.
BThe column and all its data are fully restored as before the drop.
CThe column remains dropped and data is unrecoverable.
DThe column is restored with data encrypted and inaccessible.
Attempts:
2 left
💡 Hint

Think about how databases handle dropped columns and data storage.

Practice

(1/5)
1. What does the command supabase db rollback do?
easy
A. It creates a new migration file.
B. It undoes the last applied database migration.
C. It applies all pending migrations to the database.
D. It deletes the entire database.

Solution

  1. Step 1: Understand the purpose of rollback

    Rollback means undoing changes, so this command reverses migrations already applied.
  2. Step 2: Identify the command effect

    supabase db rollback specifically undoes the last migration applied to the database.
  3. Final Answer:

    It undoes the last applied database migration. -> Option B
  4. Quick Check:

    Rollback = undo last migration [OK]
Hint: Rollback means undo last migration applied [OK]
Common Mistakes:
  • Confusing rollback with applying migrations
  • Thinking rollback creates new migrations
  • Assuming rollback deletes the database
2. Which of the following is the correct syntax to rollback the last 3 migrations using Supabase CLI?
easy
A. supabase db rollback --steps 3
B. supabase db rollback -n 3
C. supabase rollback db 3
D. supabase db undo 3

Solution

  1. Step 1: Recall the rollback command syntax

    The Supabase CLI uses --steps to specify how many migrations to rollback.
  2. Step 2: Match the correct option

    supabase db rollback --steps 3 uses supabase db rollback --steps 3, which is the correct syntax.
  3. Final Answer:

    supabase db rollback --steps 3 -> Option A
  4. Quick Check:

    Use --steps to rollback multiple migrations [OK]
Hint: Use --steps to specify rollback count [OK]
Common Mistakes:
  • Using incorrect flags like -n instead of --steps
  • Wrong command order like 'rollback db'
  • Using 'undo' instead of 'rollback'
3. Given the following commands run in order:
supabase db push
supabase db push
supabase db rollback --steps 1
What is the state of migrations after these commands?
medium
A. All migrations are rolled back except the last one.
B. No migrations are applied.
C. Both migrations are still applied.
D. Only the first migration is applied.

Solution

  1. Step 1: Apply two migrations

    Running supabase db push twice applies two migrations in order.
  2. Step 2: Rollback one migration

    The rollback with --steps 1 undoes the last applied migration, leaving the first migration applied.
  3. Final Answer:

    Only the first migration is applied. -> Option D
  4. Quick Check:

    Rollback 1 step removes last migration applied [OK]
Hint: Rollback with --steps 1 undoes last migration only [OK]
Common Mistakes:
  • Assuming rollback removes all migrations
  • Thinking rollback does not affect applied migrations
  • Confusing push and rollback order
4. You run supabase db rollback --steps 2 but get an error saying no migrations to rollback. What is the most likely cause?
medium
A. There are fewer than 2 migrations applied to rollback.
B. The migrations folder is missing.
C. The database connection is not configured.
D. Rollback command requires a --force flag.

Solution

  1. Step 1: Understand rollback error

    The error indicates no migrations to rollback, meaning none or fewer than requested are applied.
  2. Step 2: Identify cause

    If fewer than 2 migrations are applied, trying to rollback 2 steps causes this error.
  3. Final Answer:

    There are fewer than 2 migrations applied to rollback. -> Option A
  4. Quick Check:

    Rollback steps > applied migrations causes error [OK]
Hint: Check applied migrations count before rollback steps [OK]
Common Mistakes:
  • Assuming rollback always works without applied migrations
  • Thinking rollback needs --force flag
  • Ignoring database connection issues
5. You have applied 5 migrations but want to rollback only the 3rd migration without affecting others. Which approach is best?
hard
A. Delete the 3rd migration file and run supabase db push.
B. Use supabase db rollback --steps 3 to rollback only the 3rd migration.
C. Rollback all migrations from the 3rd onwards, then reapply the ones after it.
D. Directly edit the database to remove changes from the 3rd migration.

Solution

  1. Step 1: Understand migration order

    Migrations apply in order; you cannot rollback a middle migration without undoing later ones first.
  2. Step 2: Plan rollback and reapply

    Rollback migrations after the 3rd (steps 2), then rollback the 3rd, then reapply the later migrations.
  3. Final Answer:

    Rollback all migrations from the 3rd onwards, then reapply the ones after it. -> Option C
  4. Quick Check:

    Rollback middle migration requires undoing later ones first [OK]
Hint: Undo later migrations first, then rollback target migration [OK]
Common Mistakes:
  • Trying to rollback a single middle migration directly
  • Deleting migration files without rollback
  • Editing database manually causing inconsistency
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard