1
0
mirror of https://github.com/xorcare/testing-go-code-with-postgres.git synced 2024-12-24 16:28:34 +02:00
testing-go-code-with-postgres/docker-multiple-databases.sh
Vasiliy Vasilyuk cdd90f86db
Fix placeholder for the database template name
When a template database name contains invalid characters such as `-`,
the request to create a new database stops working.

To reduce this behavior, quotation marks have been added.
2023-07-15 20:34:41 +03:00

21 lines
548 B
Bash
Executable File

#!/bin/bash
set -e
set -u
function create_user_and_database() {
local database=$1
echo " Creating user and database '$database'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE DATABASE "$database" OWNER $POSTGRES_USER;
EOSQL
}
if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
for database in $(echo "$POSTGRES_MULTIPLE_DATABASES" | tr ',' ' '); do
create_user_and_database "$database"
done
echo "Multiple databases created"
fi