Skip to content

Run database migrations in pre-install,pre-upgrade hook#121

Open
andydennehy wants to merge 6 commits intolightdash:mainfrom
andydennehy:preupgrade-hook-migration
Open

Run database migrations in pre-install,pre-upgrade hook#121
andydennehy wants to merge 6 commits intolightdash:mainfrom
andydennehy:preupgrade-hook-migration

Conversation

@andydennehy
Copy link
Contributor

@andydennehy andydennehy commented Mar 16, 2026

Description

Link to issue.

This solves issue #98 by adding a pre-upgrade hook which runs pnpm -F backend migrate-production, without being constrained by startupProbe or livenessProbe.

Also, this job runs on pre-install when using an external database. To make sure all necessary environment variables are available to the migration Job, the chart creates ephemeral pre-install ConfigMap and Secret objects that are mounted into the migration container.

@andydennehy andydennehy force-pushed the preupgrade-hook-migration branch 4 times, most recently from 45c19e0 to 106a60b Compare March 17, 2026 09:25
@andydennehy andydennehy changed the title Run database migrations in pre-upgrade hook Run database migrations in post-install,pre-upgrade hook Mar 17, 2026
@andydennehy andydennehy force-pushed the preupgrade-hook-migration branch from ae33a8c to 63b0a51 Compare March 18, 2026 10:02
@andydennehy andydennehy changed the title Run database migrations in post-install,pre-upgrade hook Run database migrations in pre-install,pre-upgrade hook Mar 18, 2026
Copy link
Contributor

@almeidabbm almeidabbm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey hey!! Thank you for you contribution 🚀
This looks mostly good although I do have a couple suggestions

Also, in the PR description you mention changing the entrypoint to node dist/index.js, this change isn't here but I do think it should be kept out so that pods still run migrations if they just get their new version via a kubectl command (not upgraded via helm)

{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "lightdash.serviceAccountName" . }}
containers:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also include initContainers?
Some infra's might be using them as side car containers serving as proxy for the db which would be necessary to run migrations 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@andydennehy andydennehy force-pushed the preupgrade-hook-migration branch 2 times, most recently from a2fd74b to 3888edb Compare March 20, 2026 15:50
@andydennehy
Copy link
Contributor Author

Hey hey!! Thank you for you contribution 🚀 This looks mostly good although I do have a couple suggestions

Also, in the PR description you mention changing the entrypoint to node dist/index.js, this change isn't here but I do think it should be kept out so that pods still run migrations if they just get their new version via a kubectl command (not upgraded via helm)

Yes, that was my initial idea but we can leave it like this. It shouldn't matter as long as the migration runs before the backend pods starts...

@andydennehy andydennehy force-pushed the preupgrade-hook-migration branch from c976ed1 to 2da6b40 Compare March 20, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants