From c515754fc2adb3231e587237b6702fe216c58684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=98eho=C5=99?= Date: Tue, 5 Mar 2024 16:36:12 +0100 Subject: [PATCH] Adjusting entrypoint to allow database initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr Řehoř --- apps/postgres-init/entrypoint.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/postgres-init/entrypoint.sh b/apps/postgres-init/entrypoint.sh index 11be2b079..3e1f345c7 100755 --- a/apps/postgres-init/entrypoint.sh +++ b/apps/postgres-init/entrypoint.sh @@ -55,6 +55,14 @@ for dbname in ${INIT_POSTGRES_DBNAME}; do if [[ -z "${database_exists}" ]]; then printf "\e[1;32m%-6s\e[m\n" "Create Database ${dbname} ..." createdb --owner "${INIT_POSTGRES_USER}" "${dbname}" + database_init_file="/initdb/${dbname}.sql" + if [[ -f "$(database_init_file)" ]]; then + printf "\e[1;32m%-6s\e[m\n" "Initialize Database ..." + psql \ + --dbname "${dbname}" \ + --echo-all \ + --file "$(database_init_file)" + fi fi printf "\e[1;32m%-6s\e[m\n" "Update User Privileges on Database ..." psql --command "grant all privileges on database \"${dbname}\" to \"${INIT_POSTGRES_USER}\";"