From 366c2810b3bfcc2137f4a1d795ea2fdb8ffe31fc Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 15 Apr 2022 15:17:45 +0200 Subject: [PATCH] new: [postgres] allow relation options ``encoding``, ``lc-collate``, ``lc-ctype``, ``template`` These options are only used upon creation of the database. Signed-off-by: Valentin Lab --- postgres/hooks/postgres_database-relation-joined | 11 +++++++++-- postgres/lib/common | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/postgres/hooks/postgres_database-relation-joined b/postgres/hooks/postgres_database-relation-joined index 5dfc31a..9c23f8b 100755 --- a/postgres/hooks/postgres_database-relation-joined +++ b/postgres/hooks/postgres_database-relation-joined @@ -51,8 +51,15 @@ ensure_db_docker_running ## XXXvlab: should send all these into only one docker... if ! db_has_database "$DBNAME"; then - db_create "$DBNAME" || exit 1 - + INITDB_ARGS=(encoding lc-collate lc-ctype template) + CREATEDB_OPTS=() + for option in "${INITDB_ARGS[@]}"; do + value="$(relation-get "$option" 2>/dev/null)" || true + if [ -n "$value" ]; then + CREATEDB_OPTS+=("--$option=$value") + fi + done + db_create "$DBNAME" "${CREATEDB_OPTS[@]}" || exit 1 if sql=$(relation-get init-sql); then ddb "$DBNAME" > /dev/null < <(e "$sql") || exit 1 fi diff --git a/postgres/lib/common b/postgres/lib/common index a6feb29..20947b2 100644 --- a/postgres/lib/common +++ b/postgres/lib/common @@ -63,7 +63,8 @@ db_drop () { db_create () { local dbname="$1" - dcmd createdb "$dbname" || return 1 + shift + dcmd createdb "$dbname" "$@" || return 1 info "Database '$dbname' created." }