diff --git a/README.md b/README.md index b5353bc..a6b88c8 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,8 @@ docker run --name postgresql -itd \ The above command enables the `unaccent` and `pg_trgm` modules on the databases listed in `DB_NAME`, namely `db1` and `db2`. +Each comma separated field can contain whitespace, allowing you to set arbitrary options (such as `CASCADE` ). For full syntax, refer official documentation about [CREATE EXTENSION](https://www.postgresql.org/docs/current/sql-createextension.html). + > **NOTE**: > > This option deprecates the `DB_UNACCENT` parameter. diff --git a/runtime/functions b/runtime/functions index f6e7042..818cae1 100755 --- a/runtime/functions +++ b/runtime/functions @@ -318,10 +318,13 @@ load_extensions() { psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS unaccent;" >/dev/null 2>&1 fi - for extension in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_EXTENSION}"); do + local IFS_ORG=$IFS + IFS=, + for extension in ${DB_EXTENSION}; do echo "‣ Loading ${extension} extension..." psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS ${extension};" >/dev/null 2>&1 done + IFS=$IFS_ORG } create_database() { @@ -331,7 +334,9 @@ create_database() { echo "INFO! Database cannot be created on a $REPLICATION_MODE node. Skipping..." ;; *) - for database in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do + local IFS_ORG=$IFS + IFS=, + for database in ${DB_NAME}; do echo "Creating database: ${database}..." if [[ -z $(psql -U ${PG_USER} -Atc "SELECT 1 FROM pg_catalog.pg_database WHERE datname = '${database}'";) ]]; then psql -U ${PG_USER} -c "CREATE DATABASE \"${database}\" WITH TEMPLATE = \"${DB_TEMPLATE}\";" >/dev/null @@ -344,6 +349,7 @@ create_database() { psql -U ${PG_USER} -c "GRANT ALL PRIVILEGES ON DATABASE \"${database}\" to \"${DB_USER}\";" >/dev/null fi done + IFS=$IFS_ORG ;; esac fi