We recommend using a robust migration framework for your applications that uses versioned migration files. Most migration frameworks support linear migrations, which only allow progressive changes.Therefore, if you need to remove a database column or field introduced in an earlier migration, you must create a new
migration file specifically for this purpose. This approach ensures that all changes are tracked and applied in a
controlled and sequential manner.
Prerequisites
- A migrations docker image
- A Helm chart defining your application.
Schema Migrations
Using Helm lifecycle hooks
To satisfy the principle of having migrations run before the new application version starts, as well as ensure that only one migration job runs concurrently, we use Helm’spre-install
and pre-upgrade
hooks feature.
Helm pre-upgrade hooks are chart hooks that:Executes on an upgrade request after templates are rendered, but before any resources are updated
pre-install
and pre-upgrade
hooks to run migrations as part of our chart definition, we create a template for
a Kubernetes Job and annotate it with the relevant Helm hook annotations.
job.yaml
Above Job will be run each time when an Environment is created and when a deployment is made with a new helm chart
version.
Data Migrations
Similarly, DB data migrations can be performed within the same migration files and executed sequentially in a consistent order. This approach allows you to manage both schema and data changes together within the same migration framework, ensuring consistency and ease of development and maintenance.LocalOps intends to adopt Blue/Green deployment strategy soon. Therefore, it is advisable to avoid introducing
breaking database or API changes in consecutive deployments. This practice ensures smoother transitions and minimizes
disruptions during version upgrades.