From 0ba4f86ac50c1092005ae63cddca4c5c1493de4f Mon Sep 17 00:00:00 2001 From: James Gunn Date: Thu, 8 Aug 2024 13:18:50 +0100 Subject: [PATCH] Ensure postgres user has the replication privilege --- TeachingRecordSystem/db.sh | 2 +- terraform/aks/app.tf | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/TeachingRecordSystem/db.sh b/TeachingRecordSystem/db.sh index 7c7f9b3581..0716b6061f 100644 --- a/TeachingRecordSystem/db.sh +++ b/TeachingRecordSystem/db.sh @@ -5,4 +5,4 @@ ENV_VARS=$(env | grep DefaultConnection | sed 's/^ConnectionStrings__DefaultConn /^Password/ { print "export PGPASSWORD=" substr($0, 10) } ') eval "$ENV_VARS" -psql +psql $@ diff --git a/terraform/aks/app.tf b/terraform/aks/app.tf index 1c945242c6..7dd3c12628 100644 --- a/terraform/aks/app.tf +++ b/terraform/aks/app.tf @@ -24,13 +24,18 @@ resource "kubernetes_job" "migrations" { container { name = "cli" image = var.docker_image - command = ["trscli"] - args = ["migrate-db", "--connection-string", "$(CONNECTION_STRING)"] + command = ["/bin/ash"] + args = ["-c", "./db.sh -c 'alter user $(PG_USER) with replication;'; trscli migrate-db --connection-string $(CONNECTION_STRING);"] env { name = "CONNECTION_STRING" value = module.postgres.dotnet_connection_string } + + env { + name = "PG_USER" + value = module.postgres.username + } } restart_policy = "Never"