Skip to content

Commit

Permalink
WIP: tests.postgresql-autoupgrade: fix permission and state problems
Browse files Browse the repository at this point in the history
  • Loading branch information
osnyx committed Nov 26, 2024
1 parent 3ab3bf4 commit 2acf29b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nixos/services/postgresql/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ in {

flyingcircus.activationScripts = {
postgresql-srv = lib.stringAfter [ "users" "groups" ] ''
# postgres data dirs are referenced in the unit as ReadWritePaths and
# already need to exist at unit start
install -d -o postgres /srv/postgresql
install -d -o postgres /srv/postgresql/${cfg.majorVersion}
# keep around required postgres packages for upgrading
install -d -o postgres /nix/var/nix/gcroots/per-user/postgres
'';
};
Expand Down
10 changes: 10 additions & 0 deletions pkgs/fc/agent/fc/util/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ def prepare_upgrade(
collate=collate,
ctype=ctype,
)
if new_data_dir.exists() and len(list(new_data_dir.iterdir())) == 0:
# empty directories created at system activation time can be ignored,
# just let the upgrade process create a new one.
log.info(
"existing-empty-data-dir",
_replace_msg=(
f"New data dir {new_data_dir} is empty. Removing and recreating it."
),
)
new_data_dir.rmdir()
if new_data_dir.exists():
check_new_data_dir(
log,
Expand Down

0 comments on commit 2acf29b

Please sign in to comment.