From 2de9da2349b78d7b203383a956fc31581a3c29a9 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 2 Jun 2021 08:16:56 +0300 Subject: [PATCH] Moved ers database creation in a separate script --- data/ansible/integration_tests/main.yaml | 12 +++++++++ data/storage/mysql/create_db_with_users.sql | 6 ----- data/storage/mysql/create_ers_db.sql | 15 +++++++++++ data/storage/mysql/setup_ers_db.sh | 25 +++++++++++++++++++ data/storage/postgres/create_db_with_users.sh | 4 --- data/storage/postgres/create_ers_db.sh | 4 +++ 6 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 data/storage/mysql/create_ers_db.sql create mode 100755 data/storage/mysql/setup_ers_db.sh create mode 100755 data/storage/postgres/create_ers_db.sh diff --git a/data/ansible/integration_tests/main.yaml b/data/ansible/integration_tests/main.yaml index a8d2fb0c5..3a7c46084 100644 --- a/data/ansible/integration_tests/main.yaml +++ b/data/ansible/integration_tests/main.yaml @@ -147,12 +147,24 @@ args: chdir: '{{ cgrates_dir }}/data/storage/mysql/' + - name: post install for ers mysql + become: yes + command: 'sh {{ cgrates_dir }}/data/storage/mysql/setup_ers_db.sh root CGRateS.org localhost' + args: + chdir: '{{ cgrates_dir }}/data/storage/mysql/' + - name: post install postgres2 become: yes command: 'sh {{ cgrates_dir }}/data/storage/postgres/create_db_with_users.sh' args: chdir: '{{ cgrates_dir }}/data/storage/postgres/' + - name: post install for ers postgres + become: yes + command: 'sh {{ cgrates_dir }}/data/storage/postgres/create_ers_db.sh' + args: + chdir: '{{ cgrates_dir }}/data/storage/postgres/' + - name: post install mongo become: yes command: 'sh {{ cgrates_dir }}/data/storage/mongo/setup_cgr_db.sh' diff --git a/data/storage/mysql/create_db_with_users.sql b/data/storage/mysql/create_db_with_users.sql index 168504926..31746b604 100644 --- a/data/storage/mysql/create_db_with_users.sql +++ b/data/storage/mysql/create_db_with_users.sql @@ -7,9 +7,3 @@ DROP DATABASE IF EXISTS cgrates; CREATE DATABASE cgrates; GRANT ALL on cgrates.* TO 'cgrates'@'localhost' IDENTIFIED BY 'CGRateS.org'; - --- extra DB for ees and ers -DROP DATABASE IF EXISTS cgrates2; -CREATE DATABASE cgrates2; - -GRANT ALL on cgrates2.* TO 'cgrates'@'localhost' IDENTIFIED BY 'CGRateS.org'; diff --git a/data/storage/mysql/create_ers_db.sql b/data/storage/mysql/create_ers_db.sql new file mode 100644 index 000000000..168504926 --- /dev/null +++ b/data/storage/mysql/create_ers_db.sql @@ -0,0 +1,15 @@ + +-- +-- Sample db and users creation. Replace here with your own details +-- + +DROP DATABASE IF EXISTS cgrates; +CREATE DATABASE cgrates; + +GRANT ALL on cgrates.* TO 'cgrates'@'localhost' IDENTIFIED BY 'CGRateS.org'; + +-- extra DB for ees and ers +DROP DATABASE IF EXISTS cgrates2; +CREATE DATABASE cgrates2; + +GRANT ALL on cgrates2.* TO 'cgrates'@'localhost' IDENTIFIED BY 'CGRateS.org'; diff --git a/data/storage/mysql/setup_ers_db.sh b/data/storage/mysql/setup_ers_db.sh new file mode 100755 index 000000000..455315e3c --- /dev/null +++ b/data/storage/mysql/setup_ers_db.sh @@ -0,0 +1,25 @@ +#! /usr/bin/env sh + +if test $# -lt 2; then + echo "" + echo "setup_cgr_db.sh []" + echo "" + exit 0 +fi + +host=$3 +if [ -z "$3" ]; then + host="localhost" +fi + +DIR="$(dirname "$(readlink -f "$0")")" + +mysql -u $1 -p$2 -h $host < "$DIR"/create_ers_db.sql +cu=$? + +if [ $cu = 0 ]; then + echo "\n\t+++ CGR-DB successfully set-up! +++\n" + exit 0 +fi + + diff --git a/data/storage/postgres/create_db_with_users.sh b/data/storage/postgres/create_db_with_users.sh index 03947cebd..484290ec1 100755 --- a/data/storage/postgres/create_db_with_users.sh +++ b/data/storage/postgres/create_db_with_users.sh @@ -7,7 +7,3 @@ sudo -u postgres dropdb -e cgrates sudo -u postgres dropuser -e cgrates sudo -u postgres psql -c "CREATE USER cgrates password 'CGRateS.org';" sudo -u postgres createdb -e -O cgrates cgrates - -# extra DB for ees and ers -sudo -u postgres dropdb -e cgrates2 -sudo -u postgres createdb -e -O cgrates cgrates2 diff --git a/data/storage/postgres/create_ers_db.sh b/data/storage/postgres/create_ers_db.sh new file mode 100755 index 000000000..c697fa9d5 --- /dev/null +++ b/data/storage/postgres/create_ers_db.sh @@ -0,0 +1,4 @@ + +# extra DB for ees and ers +sudo -u postgres dropdb -e cgrates2 +sudo -u postgres createdb -e -O cgrates cgrates2