Why migrations version your database schema in Supabase - Performance Analysis
When we change a database schema, migrations keep track of each change step by step.
We want to understand how the work grows as we add more migration steps.
Analyze the time complexity of applying migrations to update a database schema.
// Example migration application sequence
const { data, error } = await supabase.rpc('apply_migration', { version: currentVersion + 1 });
if (error) throw error;
// Repeat until latest version
This sequence applies each migration one by one to update the schema to the latest version.
Each migration step involves:
- Primary operation: Calling the migration function to apply one schema change.
- How many times: Once per migration version that needs applying.
As the number of migration versions increases, the number of calls grows the same way.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 migration calls |
| 100 | 100 migration calls |
| 1000 | 1000 migration calls |
Pattern observation: The work grows directly with the number of migration steps.
Time Complexity: O(n)
This means the time to update the schema grows in a straight line as you add more migration versions.
[X] Wrong: "Applying migrations happens all at once, so time stays the same no matter how many versions."
[OK] Correct: Each migration must be applied in order, so more versions mean more steps and more time.
Understanding how migrations scale helps you explain how database updates affect deployment time and reliability.
"What if migrations could be applied in parallel? How would the time complexity change?"