From 3b3e47f94b28ae1e6053a69d022d137450259c7a Mon Sep 17 00:00:00 2001 From: Omar Date: Tue, 19 Mar 2024 12:12:20 +0100 Subject: [PATCH 1/2] Add script to create database --- scripts/create-database.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 scripts/create-database.sh diff --git a/scripts/create-database.sh b/scripts/create-database.sh new file mode 100755 index 0000000..f176cf1 --- /dev/null +++ b/scripts/create-database.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# Creates secondary database. Usage: ./scripts/create-database legacy +set -e + +DB_NAME=$1 +PROJECT_ROOT="./" +MYSQL_ROOT_PASS=`egrep DB_ROOT_PASSWORD ${PROJECT_ROOT}/.env | sed s/DB_ROOT_PASSWORD=//` +MYSQL_HOST=`egrep DB_HOST ${PROJECT_ROOT}/.env | sed s/DB_HOST=//` + +docker compose exec mariadb mysql -u root -p${MYSQL_ROOT_PASS} -h ${MYSQL_HOST} -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME};GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO 'drupal'@'%';" From bff202f186e49021e7fdd9fab3cf79dcf04c3135 Mon Sep 17 00:00:00 2001 From: Omar Date: Tue, 19 Mar 2024 12:42:10 +0100 Subject: [PATCH 2/2] Add -T parameters to make create-database works on CD/CI --- scripts/create-database.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create-database.sh b/scripts/create-database.sh index f176cf1..4d54b90 100755 --- a/scripts/create-database.sh +++ b/scripts/create-database.sh @@ -8,4 +8,4 @@ PROJECT_ROOT="./" MYSQL_ROOT_PASS=`egrep DB_ROOT_PASSWORD ${PROJECT_ROOT}/.env | sed s/DB_ROOT_PASSWORD=//` MYSQL_HOST=`egrep DB_HOST ${PROJECT_ROOT}/.env | sed s/DB_HOST=//` -docker compose exec mariadb mysql -u root -p${MYSQL_ROOT_PASS} -h ${MYSQL_HOST} -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME};GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO 'drupal'@'%';" +docker compose exec -T mariadb mysql -u root -p${MYSQL_ROOT_PASS} -h ${MYSQL_HOST} -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME};GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO 'drupal'@'%';"