You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Programmatic method to apply migrations before server start #3873
Currently, database migrations in Serverpod can only be applied as part of the server startup process. This limits workflows where a developer needs to apply migrations before starting the server, for example data transformations that depend on the new schema.
Proposal
Introduce a dedicated method (e.g., applyMigrations()) that can be called programmatically without starting the server. This method should:
Use the same logic as migrations during startup.
Apply only pending migrations.
Be idempotent to prevent reapplying completed migrations.
Provide clear feedback on applied changes and any errors.
This dedicated method could possibly live under a maintenance namespace that allows other maintenance mode operations such as running all scheduled future calls, performing the health check, and updating the log settings.
Use Case
A developer wants to apply the latest schema changes, then run a one-off Dart script to backfill or transform data before starting the server. This avoids starting the server in a partially migrated state.
Alternatives
Manually starting the server with migrations enabled, then stopping it to perform pre-startup tasks. This is inefficient and risks unexpected behavior if the server begins handling requests during the migration process.
Additional context
How experienced are you with this library?
Expert - Experienced and comfortable with using this library in complex projects
Should this maybe be designed in conjunction with the service lifecycle interface? E.g. standardizing something along these lines:
Serverpod object creation
Configurations ingestion
Backend services initialization (connecting to backend services like DB and Redis)
Migrations
Start serving requests (incl future calls)
Today there is only 1 and 5 with user-added "stuff" in between. A well-defined pattern on how to do this, how to add new services to this process, and inject tasks pre/post these steps would be nice!
Activity
christerswahn commentedon Aug 11, 2025
Should this maybe be designed in conjunction with the service lifecycle interface? E.g. standardizing something along these lines:
Today there is only 1 and 5 with user-added "stuff" in between. A well-defined pattern on how to do this, how to add new services to this process, and inject tasks pre/post these steps would be nice!