Running migrations locally and remotely in Supabase - Time & Space Complexity
When running database migrations with Supabase, it is important to understand how the time taken grows as the number of migrations increases.
We want to know how the process scales when applying migrations locally and remotely.
Analyze the time complexity of the following operation sequence.
// Run migrations locally
supabase db reset
// Run migrations remotely
supabase db push
This sequence applies all pending migrations first locally, then pushes them to the remote Supabase database.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Applying each migration script one by one to the database.
- How many times: Once per migration file in the migration folder.
As the number of migrations increases, the total time grows roughly in direct proportion.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 migration applies + 1 reset + 1 push |
| 100 | 100 migration applies + 1 reset + 1 push |
| 1000 | 1000 migration applies + 1 reset + 1 push |
Pattern observation: The number of migration applies grows linearly with the number of migrations, while reset and push happen once.
Time Complexity: O(n)
This means the time to run migrations grows directly with the number of migration files.
[X] Wrong: "Running migrations remotely takes the same time regardless of how many migrations there are."
[OK] Correct: Each migration must be applied in order, so more migrations mean more work and longer time.
Understanding how migration time grows helps you plan deployment steps and communicate realistic timelines in real projects.
"What if migrations were batched and applied all at once? How would the time complexity change?"