Run database migrations only when pending - #798
Conversation
There was a problem hiding this comment.
Ack, similar approach I suggested in #769 (comment)
|
I really wish we could run |
We can. I tried this approach as well and it works. It's just not as efficient because booting our environment is slow. When I researched how to make our boot time faster I basically encountered needing to go explore bootsnap which we only enable in development. Based on the time savings of other big apps (e.g. Shopify) we could possibly get our boot time down to sub 5 seconds. |
|
Stupid question: Why can't we migrate on app boot (so in |
I think we avoided this primarily due to potential race conditions with Puma having multiple workers, the need to ensure orchestration of the foreman instance before dynflow, and to keep the door open to multi-container instances in the future. |
|
So I realized there is a signal missing in this design that would cause problems and that is if a feature is enabled that enables a plugin this would not signal the migration. That leaves us with two options:
|
c4e7e25 to
e4c85c5
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughForeman and Pulp now check for pending database migrations before running migration services. Foreman removes migration ordering dependencies and no longer seeds during migration. Pulp adds a configurable always-run option. ChangesDatabase migration gating
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to Foreman and Pulp now avoid unnecessary migration runs while preserving Pulp’s existing always-run behavior by default. No actionable merge-blocking risk remains. Sequence Diagram(s)sequenceDiagram
participant ForemanRoleTasks
participant ForemanMigrationCheckService
participant ForemanDatabase
participant ForemanMigrationService
ForemanRoleTasks->>ForemanMigrationCheckService: restart migration check
ForemanMigrationCheckService->>ForemanDatabase: run db:abort_if_pending_migrations
ForemanRoleTasks->>ForemanMigrationCheckService: read ExecMainStatus
ForemanRoleTasks->>ForemanMigrationService: restart when status is 1
sequenceDiagram
participant PulpRoleTasks
participant PulpMigrationCheckService
participant PulpDatabase
participant PulpMigrationService
PulpRoleTasks->>PulpMigrationCheckService: restart when always-run is false
PulpMigrationCheckService->>PulpDatabase: run pulpcore-manager migrate --check
PulpRoleTasks->>PulpMigrationCheckService: read ExecMainStatus
PulpRoleTasks->>PulpMigrationService: migrate when status is 1 or always-run is true
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5de9317 to
0048e96
Compare
|
I have reworked this to the check if there are pending migrations model as that is the most reliable. I tried out checking for image change or quadlet change but those both still felt like there could be edge cases. |
0048e96 to
179b4f1
Compare
| pulp_enable_analytics: false | ||
| pulp_mirror: false | ||
| pulp_register_foreman_proxy: true | ||
| # Pulp post-migration hooks must run even when there are no pending migrations. |
There was a problem hiding this comment.
If it must always run, why bother checking if it needs to run? :)
There was a problem hiding this comment.
Great question, this came from https://github.com/theforeman/puppet-pulpcore/blob/master/manifests/database.pp#L39. Re-reading the PR (theforeman/puppet-pulpcore#351) I see we did this as a quirk of puppet idempotency.
There was a problem hiding this comment.
I removed the Pulp handling from the code, this just does Foreman now.
179b4f1 to
4cff9cc
Compare
Why are you introducing these changes? (Problem description, related links)
Foreman database migration containers currently run on deployments where their databases are already up to date. These containers add unnecessary startup time. Database migrations should be checked explicitly, and the migration containers should only run when pending migrations are reported.
What are the changes introduced in this pull request?
How to test this pull request
Steps to reproduce:
ANSIBLE_COLLECTIONS_PATH="$PWD/build/collections/foremanctl" ANSIBLE_COLLECTIONS_SCAN_SYS_PATH=false bash -c 'source .venv/bin/activate && cd src && ansible-lint'; expect no findings.source .venv/bin/activate && ruff check tests/ src/ development/scripts/ inventories/; expect all checks to pass.git diff --check; expect no whitespace errors.Checklist