Skip to content

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

Merged
almeidabbm merged 11 commits into
lightdash:mainfrom
andydennehy:preupgrade-hook-migration
Mar 23, 2026
Merged

almeidabbm merged 11 commits into
lightdash:mainfrom
andydennehy:preupgrade-hook-migration

Conversation

@andydennehy

@andydennehy andydennehy commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

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

@almeidabbm almeidabbm left a comment

Copy link
Copy Markdown
Contributor

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)

Comment thread charts/lightdash/templates/migrationJob.yaml
Comment thread charts/lightdash/templates/configmap.yaml Outdated
Comment thread charts/lightdash/templates/secrets.yaml Outdated
Comment thread charts/lightdash/templates/serviceAccount.yaml Outdated
@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
Copy Markdown
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

@almeidabbm almeidabbm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a migrationJob.enabled value and conditionally render all the templates:

  • configmap
  • secrets
  • serviceAccount
  • migration job

This way someone could opt out of running this job and render the resources

Also, we should bump the version in charts/lightdash/Chart.yaml and charts/lightdash/README.md like - here's a PR with the example https://github.com/lightdash/helm-charts/pull/120/changes

Comment thread charts/lightdash/templates/migrationJob.yaml Outdated
@andydennehy
andydennehy force-pushed the preupgrade-hook-migration branch 4 times, most recently from cec113e to 76fda3f Compare March 23, 2026 13:04
@andydennehy
andydennehy force-pushed the preupgrade-hook-migration branch from 76fda3f to c101349 Compare March 23, 2026 13:09

@almeidabbm almeidabbm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🚀

Rendering test results:

  Results:

  ┌─────────────────────────────────┬─────────────────────────────────────────────────────┐
  │            Scenario             │                       Outcome                       │
  ├─────────────────────────────────┼─────────────────────────────────────────────────────┤
  │ Default values                  │ All 4 migration resources render correctly          │
  ├─────────────────────────────────┼─────────────────────────────────────────────────────┤
  │ migrationJob.enabled: false     │ Nothing renders — clean                             │
  ├─────────────────────────────────┼─────────────────────────────────────────────────────┤
  │ migrationJob: {} (empty object) │ Renders fine — Helm deep-merges with chart defaults │
  ├─────────────────────────────────┼─────────────────────────────────────────────────────┤
  │ migrationJob: null              │ Nil pointer error on migrationServiceAccount.yaml:1 - same pattern as scheduler │
  └─────────────────────────────────┴─────────────────────────────────────────────────────┘

@almeidabbm
almeidabbm merged commit 539a962 into lightdash:main Mar 23, 2026
2 of 6 checks passed
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