From 5750cffe769f904d7431c7fa7df44ab78d61b17d Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 13 Aug 2024 10:47:57 +0200 Subject: [PATCH 1/2] Always run pulpcore-manager migrate Pulpcore uses post migration hooks to create data in the database, which sometimes changes even if there are no real migrations to be run. This is fine from a Django PoV -- post migration hooks run after every `migrate` call, even if there have been no changes. However, this means that we need to run `migrate` unconditionally as otherwise we might miss changes to the hooks (or their data) when there is no migration attached. An example of such a change is https://github.com/pulp/pulpcore/commit/20cffca49de5f3bfac44e0160c1f0fb262141ea5 where a new role was introduced and our setup started failing as it was expecting the role to exist after the upgrade, but it did not as we did not call `migrate`. --- manifests/database.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/manifests/database.pp b/manifests/database.pp index 28da3e2..3709ab7 100644 --- a/manifests/database.pp +++ b/manifests/database.pp @@ -30,7 +30,6 @@ pulpcore::admin { 'migrate --noinput': timeout => $timeout, - unless => 'pulpcore-manager migrate --check', refreshonly => false, } From 68361331c6e73c9959e8844ce40d14cb69875ef0 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 14 Aug 2024 10:31:15 +0200 Subject: [PATCH 2/2] Allow disabling migration re-runs to make things idempotent --- manifests/database.pp | 10 ++++++++++ spec/acceptance/hieradata/common.yaml | 1 + 2 files changed, 11 insertions(+) diff --git a/manifests/database.pp b/manifests/database.pp index 3709ab7..3a9bd72 100644 --- a/manifests/database.pp +++ b/manifests/database.pp @@ -2,6 +2,7 @@ # @api private class pulpcore::database ( Integer[0] $timeout = 3600, + Boolean $always_run_migrations = true, ) { if $pulpcore::postgresql_manage_db { include postgresql::client @@ -28,8 +29,17 @@ Class['postgresql::server::service'] ~> Service['pulpcore-content.service'] } + # By default we want to always run `migrate`, even if `--check` returns no pending migrations + # This is due to the fact that Pulp uses post_migration hooks that need to be executed even + # when no real migration has happened. + $migrate_unless = $always_run_migrations ? { + false => 'pulpcore-manager migrate --check', + default => undef, + } + pulpcore::admin { 'migrate --noinput': timeout => $timeout, + unless => $migrate_unless, refreshonly => false, } diff --git a/spec/acceptance/hieradata/common.yaml b/spec/acceptance/hieradata/common.yaml index 72518b1..411c62f 100644 --- a/spec/acceptance/hieradata/common.yaml +++ b/spec/acceptance/hieradata/common.yaml @@ -3,3 +3,4 @@ apache::default_mods: false pulpcore::apache_https_cert: '/etc/pulpcore-certs/ca-cert.pem' pulpcore::apache_https_key: '/etc/pulpcore-certs/ca-key.pem' pulpcore::apache_https_ca: '/etc/pulpcore-certs/ca-cert.pem' +pulpcore::database::always_run_migrations: false