aboutsummaryrefslogtreecommitdiff
path: root/hosts
diff options
context:
space:
mode:
authorIsabella Bastaja <isabella@sorre.xyz>2025-12-25 14:52:10 +0100
committerIsabella Bastaja <isabella@sorre.xyz>2025-12-25 14:52:39 +0100
commitbfb38c54b990774b1995ef700ab6509c2f993a76 (patch)
tree8fc4703b1fff9732a4b775d15503a63534b31511 /hosts
parent9586392491946f33f1450d4cc2d7e5315673a780 (diff)
sagittarius: add postgres upgrade script
Diffstat (limited to 'hosts')
-rw-r--r--hosts/sagittarius/web/mediadb.nix32
1 files changed, 31 insertions, 1 deletions
diff --git a/hosts/sagittarius/web/mediadb.nix b/hosts/sagittarius/web/mediadb.nix
index 3c5c111..90c95d6 100644
--- a/hosts/sagittarius/web/mediadb.nix
+++ b/hosts/sagittarius/web/mediadb.nix
@@ -1,4 +1,32 @@
-{ pkgs, ... }:
+{
+ pkgs,
+ lib,
+ config,
+ ...
+}:
+let
+ newPostgres = pkgs.postgresql_18_jit;
+ cfg = config.services.postgresql;
+ upgrade-pg-cluster = pkgs.writeScriptBin "upgrade-pg-cluster" ''
+ set -eux
+ systemctl stop postgresql
+
+ export NEWDATA="/var/lib/postgresql/${newPostgres.psqlSchema}"
+ export NEWBIN="${newPostgres}/bin"
+
+ export OLDDATA="${cfg.dataDir}"
+ export OLDBIN="${cfg.finalPackage}/bin"
+
+ install -d -m 0700 -o postgres -g postgres "$NEWDATA"
+ cd "$NEWDATA"
+ sudo -u postgres "$NEWBIN/initdb" -D "$NEWDATA" ${lib.escapeShellArgs cfg.initdbArgs}
+
+ sudo -u postgres "$NEWBIN/pg_upgrade" \
+ --old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
+ --old-bindir "$OLDBIN" --new-bindir "$NEWBIN" \
+ "$@"
+ '';
+in
{
networking.firewall.allowedTCPPorts = [ 5432 ];
@@ -19,4 +47,6 @@
host all all all scram-sha-256
'';
}; # end of services.postgreslq
+
+ environment.systemPackages = [ upgrade-pg-cluster ];
}