Add migration for postgresql 13->15 after migrating to bookworm

This commit is contained in:
Alexandre Aubin 2024-07-03 20:20:16 +02:00
parent 1a85521f1f
commit 4b8506f71f

View file

@ -13,9 +13,9 @@ logger = getLogger("yunohost.migration")
class MyMigration(Migration):
"Migrate DBs from Postgresql 11 to 13 after migrating to Bullseye"
"Migrate DBs from Postgresql 13 to 15 after migrating to Bookworm"
dependencies = ["migrate_to_bullseye"]
dependencies = ["migrate_to_bookworm"]
def run(self):
if (
@ -27,37 +27,37 @@ class MyMigration(Migration):
logger.info("No YunoHost app seem to require postgresql... Skipping!")
return
if not self.package_is_installed("postgresql-11"):
logger.warning(m18n.n("migration_0023_postgresql_11_not_installed"))
if not self.package_is_installed("postgresql-13"):
logger.warning(m18n.n("migration_0029_postgresql_13_not_installed"))
return
if not self.package_is_installed("postgresql-13"):
raise YunohostValidationError("migration_0023_postgresql_13_not_installed")
if not self.package_is_installed("postgresql-15"):
raise YunohostValidationError("migration_0029_postgresql_15_not_installed")
# Make sure there's a 11 cluster
# Make sure there's a 13 cluster
try:
self.runcmd("pg_lsclusters | grep -q '^11 '")
self.runcmd("pg_lsclusters | grep -q '^13 '")
except Exception:
logger.warning(
"It looks like there's not active 11 cluster, so probably don't need to run this migration"
"It looks like there's not active 13 cluster, so probably don't need to run this migration"
)
return
if not space_used_by_directory(
"/var/lib/postgresql/11"
"/var/lib/postgresql/13"
) > free_space_in_directory("/var/lib/postgresql"):
raise YunohostValidationError(
"migration_0023_not_enough_space", path="/var/lib/postgresql/"
"migration_0029_not_enough_space", path="/var/lib/postgresql/"
)
self.runcmd("systemctl stop postgresql")
time.sleep(3)
self.runcmd(
"LC_ALL=C pg_dropcluster --stop 13 main || true"
) # We do not trigger an exception if the command fails because that probably means cluster 13 doesn't exists, which is fine because it's created during the pg_upgradecluster)
"LC_ALL=C pg_dropcluster --stop 15 main || true"
) # We do not trigger an exception if the command fails because that probably means cluster 15 doesn't exists, which is fine because it's created during the pg_upgradecluster)
time.sleep(3)
self.runcmd("LC_ALL=C pg_upgradecluster -m upgrade 11 main")
self.runcmd("LC_ALL=C pg_dropcluster --stop 11 main")
self.runcmd("LC_ALL=C pg_upgradecluster -m upgrade 13 main")
self.runcmd("LC_ALL=C pg_dropcluster --stop 13 main")
self.runcmd("systemctl start postgresql")
def package_is_installed(self, package_name):