Bird
Raised Fist0
Supabasecloud~20 mins

Creating migrations in Supabase - Practice Exercises

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 supabase db push with no new migration files?

You have an existing Supabase project with migrations applied. You run the command supabase db push but have not added any new migration files. What is the expected behavior?

AThe command detects no new migrations and makes no changes to the database schema.
BThe command applies all existing migrations again, duplicating schema changes.
CThe command deletes all existing tables and recreates them from scratch.
DThe command throws an error indicating no migration files found.
Attempts:
2 left
💡 Hint

Think about what happens if there is nothing new to apply.

❓ Configuration
intermediate
2:00remaining
Which file must be updated to configure the database connection for Supabase migrations?

To run migrations with Supabase CLI, you need to specify the database connection details. Which configuration file is used to set the connection string for migrations?

Asupabase/config.toml
Bsupabase/.dbconfig
Csupabase/migrations.yaml
D.env
Attempts:
2 left
💡 Hint

Supabase uses environment variables for sensitive info.

❓ Architecture
advanced
3:00remaining
What is the best practice for organizing migration files in a Supabase project?

Consider a Supabase project with multiple developers working on database schema changes. How should migration files be organized to avoid conflicts and ensure smooth deployment?

AEach developer keeps migration files locally and runs them manually without sharing.
BStore all migration files in a single folder with timestamped filenames and commit them to version control.
CUse a single migration file for all changes and overwrite it for every update.
DStore migration files outside the project folder to avoid accidental commits.
Attempts:
2 left
💡 Hint

Think about collaboration and version control.

❓ security
advanced
3:00remaining
Which practice improves security when managing Supabase migration files?

When handling migration files that include sensitive schema changes, which practice helps protect sensitive information?

AAvoid including sensitive data like passwords or secrets directly in migration files.
BStore migration files in a public repository for transparency.
CInclude database credentials inside migration SQL scripts for automation.
DEncrypt migration files before committing to version control.
Attempts:
2 left
💡 Hint

Think about what should never be in code files.

🧠 Conceptual
expert
3:00remaining
What is the effect of running supabase db reset in a project with existing migrations?

You run supabase db reset in your project directory. What happens to your database and migration files?

AMigration files are deleted but the database remains unchanged.
BOnly the last migration is applied to the existing database without dropping it.
CThe database is dropped and recreated, then all migrations are reapplied from the first to last.
DThe command only clears the migration history without affecting the database schema.
Attempts:
2 left
💡 Hint

Consider what 'reset' usually means for a database.

Practice

(1/5)
1. What is the main purpose of creating migrations in Supabase?
easy
A. To save and track changes made to the database structure
B. To create user accounts automatically
C. To deploy frontend code to the server
D. To monitor server uptime and performance

Solution

  1. Step 1: Understand what migrations do

    Migrations are files that record changes to the database schema over time.
  2. Step 2: Identify the purpose in Supabase context

    Supabase uses migrations to save and track database structure changes so they can be applied consistently.
  3. Final Answer:

    To save and track changes made to the database structure -> Option A
  4. Quick Check:

    Migrations = track database changes [OK]
Hint: Migrations always track database structure changes [OK]
Common Mistakes:
  • Confusing migrations with user management
  • Thinking migrations deploy frontend code
  • Assuming migrations monitor server health
2. Which command creates a new migration file in Supabase?
easy
A. supabase migration up
B. supabase db push
C. supabase migration new
D. supabase start migration

Solution

  1. Step 1: Recall Supabase migration commands

    The command to create a new migration file is specifically designed to generate the file for changes.
  2. Step 2: Match command to action

    supabase migration new creates a new migration file, while others apply or push changes.
  3. Final Answer:

    supabase migration new -> Option C
  4. Quick Check:

    Create migration file = supabase migration new [OK]
Hint: New migration files use 'migration new' command [OK]
Common Mistakes:
  • Using 'db push' to create migration files
  • Confusing 'migration up' with creation
  • Typing incorrect commands like 'start migration'
3. After creating a migration file, which command applies the changes to your remote database?
medium
A. supabase migration up
B. supabase db push
C. supabase migration new
D. supabase db pull

Solution

  1. Step 1: Understand commands for applying migrations

    supabase db push applies schema changes to the remote database by pushing local migrations.
  2. Step 2: Differentiate commands

    supabase migration up applies migrations locally, while supabase db push pushes changes remotely.
  3. Final Answer:

    supabase db push -> Option B
  4. Quick Check:

    Apply remotely = db push [OK]
Hint: Use 'supabase db push' to apply migrations remotely [OK]
Common Mistakes:
  • Using 'supabase migration up' to apply migrations remotely
  • Confusing 'migration new' as apply command
  • Thinking 'db pull' applies migrations
4. You ran supabase migration up but got an error saying migrations are missing. What is the likely cause?
medium
A. You used the wrong command to apply locally
B. You need to restart the Supabase server
C. Your database connection is offline
D. You forgot to create migration files before applying

Solution

  1. Step 1: Analyze the error about missing migrations

    The error indicates no migration files exist to apply locally.
  2. Step 2: Identify the cause

    This usually happens if migration files were never created with supabase migration new.
  3. Final Answer:

    You forgot to create migration files before applying -> Option D
  4. Quick Check:

    Missing migrations = no files created [OK]
Hint: Create migration files before applying locally [OK]
Common Mistakes:
  • Assuming connection issues cause missing migrations
  • Restarting server without creating files
  • Confusing local and remote apply commands
5. You want to update your remote Supabase database with new schema changes. Which sequence of commands should you run?
hard
A. supabase migration new -> supabase start -> supabase migration up
B. supabase db push -> supabase migration new -> supabase migration up
C. supabase migration up -> supabase migration new -> supabase db push
D. supabase migration new -> supabase migration up -> supabase db push

Solution

  1. Step 1: Create migration files first

    Use supabase migration new to save schema changes as migration files.
  2. Step 2: Apply changes locally

    Run supabase start to update your local database with these changes.
  3. Step 3: Apply migrations remotely

    Finally, run supabase migration up to update the remote database.
  4. Final Answer:

    supabase migration new -> supabase start -> supabase migration up -> Option A
  5. Quick Check:

    Create -> local start -> remote up [OK]
Hint: Create migration, start locally, then up remotely [OK]
Common Mistakes:
  • Applying migrations before creating files
  • Applying remotely before local test
  • Mixing order of commands
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