How to run one-off tasks like database migrations with Qovery?
Last updated: February 7, 2025
Context
When managing applications, you may need to run one-off tasks like database migrations or data transformations.
Answer
There are two recommended approaches to handle one-off tasks in Qovery:
Option 1: Application Startup Migration
You can manage the task during your application startup process. When using this approach:
Configure Kubernetes health check probes properly to indicate that your application isn't ready until the task completes
Be aware of potential race conditions if you're running multiple application instances
For detailed guidance on configuring health checks, refer to our guide on achieving zero-downtime applications with Kubernetes.
Option 2: Lifecycle Jobs (Recommended)
Create a lifecycle job to manage your one-off tasks:
Set up a lifecycle job that runs before your main application deployment stage
Configure the job to trigger on the 'Deploy' event
Deploy the job alongside your application to ensure the task runs before the new application version is deployed
Important: In both approaches, ensure your application is compatible with both the new and previous versions of your data schema or configuration.