Skip to content

Commit

Permalink
Try to get the multiple db create feature working (split into array, …
Browse files Browse the repository at this point in the history
…ignore commas)
  • Loading branch information
Peter Kionga-Kamau committed Oct 9, 2024
1 parent 2aad36c commit a7fcdc2
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions templates/mariadb/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ services:
command: >
/bin/bash -c "
if [ ! -f /docker-entrypoint-initdb.d/init.sql ]; then
MYSQL_DATABASE_TRIMMED=\$$(echo \"${MYSQL_DATABASE}\" | tr -s ' ' | xargs); # trim & normalize spaces:
MYSQL_DATABASE_TRIMMED=\$$(echo \"${MYSQL_DATABASE_TRIMMED}\" | sed '/^.*,/!s/ /, /g'); # insert commas if there are none separating dbs
MYSQL_DATABASE_TRIMMED=\$$(echo \"${MYSQL_DATABASE}\" | tr -s ' ' | xargs | sed 's/,//g'); # trim & normalize spaces
IFS=' ' read -ra ADDR <<< $${MYSQL_DATABASE_TRIMMED};
for i in \"\$${ADDR[@]}\"; do # create all databases (separated by spaces in .env - not supported by mysql 5.7):
echo \"CREATE DATABASE IF NOT EXISTS \$${i}; GRANT ALL PRIVILEGES ON \\\`\$${i}\\\`.* TO '\$${MYSQL_USER}'@'%' WITH GRANT OPTION;\" >> /docker-entrypoint-initdb.d/init.sql;
Expand Down

0 comments on commit a7fcdc2

Please sign in to comment.