-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
maintenance: add postgresql schema update guide
- Loading branch information
1 parent
8969ed9
commit 958e7a5
Showing
3 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
baseSystemConfig: | ||
rec { | ||
updatePostgresql = { pkgs, postgresqlOld, postgresqlNew }: | ||
pkgs.writers.writeBash "update-postgresql" '' | ||
set -euxo pipefail | ||
systemctl stop postgresql | ||
oldData="/var/lib/postgresql/${postgresqlOld.psqlSchema}" | ||
newData="/var/lib/postgresql/${postgresqlNew.psqlSchema}" | ||
oldBin="${postgresqlOld}/bin" | ||
newBin="${postgresqlNew}/bin" | ||
install -d -m 700 -o postgres -g postgres "$newData" | ||
cd "$newData" | ||
sudo -u postgres $newBin/initdb -D "$newData" | ||
sudo -u postgres $newBin/pg_upgrade \ | ||
--old-datadir "$oldData" --new-datadir "$newData" \ | ||
--old-bindir $oldBin --new-bindir $newBin \ | ||
--jobs $(nproc) \ | ||
--link \ | ||
"$@" | ||
''; | ||
|
||
# Todo: Use the main system here when we've switched to flake-based deployment | ||
base = baseSystemConfig; | ||
|
||
baseWithPostgresql = base.extendModules { | ||
modules = [{ services.postgresql.enable = true; }]; | ||
}; | ||
|
||
updateSystem = newSystemStateVersion: | ||
let | ||
baseNewStateVersion = baseWithPostgresql.extendModules { | ||
modules = [ ({ lib, ... }: { | ||
system.stateVersion = lib.mkForce newSystemStateVersion; | ||
})]; | ||
}; | ||
in | ||
updatePostgresql { | ||
pkgs = base.pkgs; | ||
postgresqlOld = baseWithPostgresql.config.services.postgresql.package; | ||
postgresqlNew = baseNewStateVersion.config.services.postgresql.package; | ||
}; | ||
|
||
systemPostgresqlSchema = baseWithPostgresql.config.services.postgresql.package.psqlSchema; | ||
} |