From 4c43b0173969520e1227efcf9f2a0453c23f6088 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Sun, 6 May 2018 11:50:45 +0400 Subject: [PATCH] =?UTF-8?q?sqlmig:=20mode=20d=C3=A9pendant=20du=20profil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/default/sqlmig | 4 +++ sqlmig | 61 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/lib/default/sqlmig b/lib/default/sqlmig index 19a988e..a64019f 100644 --- a/lib/default/sqlmig +++ b/lib/default/sqlmig @@ -5,3 +5,7 @@ # Répertoire des profils #PROFILEDIR=/etc/sqlmig + +# Mapping profil/mode +#prod_PROFILE_MODE=prod +#test_PROFILE_MODE=devel diff --git a/sqlmig b/sqlmig index 2725d91..7e0917a 100755 --- a/sqlmig +++ b/sqlmig @@ -80,7 +80,9 @@ OPTIONS Quand un profil est activé, les fichiers de configuration par défaut deviennent respectivement \$PROFILE-my.cnf et \$PROFILE-ora.conf au lieu de my.cnf et ora.conf. De plus, ces fichiers sont aussi recherchés dans - le répertoire /etc/sqlmig + le répertoire /etc/sqlmig, en fonction du mode: en mode production, on + cherche d'abord dans /etc/sqlmig. En mode développement, on cherche + d'abord dans le répertoire local. --mysql --oracle @@ -221,7 +223,14 @@ function ensure_dbtype() { function ensure_dbmode() { local dbtype="$1" mode="$2" if [ "$mode" == auto ]; then - if [ "$dbtype" == mysql ]; then + local profile_mode + if [ -n "$profile" ]; then + profile_mode="${profile}_PROFILE_MODE" + profile_mode="${!profile_mode}" + fi + if [ -n "$profile_mode" ]; then + dbmode="$profile_mode" + elif [ "$dbtype" == mysql ]; then is_root && dbmode=prod || dbmode=devel else dbmode=prod @@ -333,15 +342,22 @@ function mysql_after_update() { function mysql_get_defaults() { local dir="$1" - if [ -z "$profile" ]; then - echo "$dir/my.cnf" - elif [ -f "$dir/${profile}-my.cnf" ]; then - echo "$dir/${profile}-my.cnf" - elif [ -f "$PROFILEDIR/${profile}-my.cnf" ]; then - echo "$PROFILEDIR/${profile}-my.cnf" - else - echo "$dir/my.cnf" + if [ -n "$profile" ]; then + if [ "$dbmode" == devel ]; then + if [ -f "$dir/${profile}-my.cnf" ]; then + echo "$dir/${profile}-my.cnf"; return + elif [ -f "$PROFILEDIR/${profile}-my.cnf" ]; then + echo "$PROFILEDIR/${profile}-my.cnf"; return + fi + else + if [ -f "$PROFILEDIR/${profile}-my.cnf" ]; then + echo "$PROFILEDIR/${profile}-my.cnf"; return + elif [ -f "$dir/${profile}-my.cnf" ]; then + echo "$dir/${profile}-my.cnf"; return + fi + fi fi + echo "$dir/my.cnf" } function mysql_set_adminargs() { local dir="$1" defaults @@ -632,15 +648,22 @@ function oracle_ensure_opdir() { } function oracle_get_defaults() { local dir="$1" - if [ -z "$profile" ]; then - echo "$dir/ora.conf" - elif [ -f "$dir/${profile}-ora.conf" ]; then - echo "$dir/${profile}-ora.conf" - elif [ -f "$PROFILEDIR/${profile}-ora.conf" ]; then - echo "$PROFILEDIR/${profile}-ora.conf" - else - echo "$dir/ora.conf" + if [ -n "$profile" ]; then + if [ "$dbmode" == devel ]; then + if [ -f "$dir/${profile}-ora.conf" ]; then + echo "$dir/${profile}-ora.conf"; return + elif [ -f "$PROFILEDIR/${profile}-ora.conf" ]; then + echo "$PROFILEDIR/${profile}-ora.conf"; return + fi + else + if [ -f "$PROFILEDIR/${profile}-ora.conf" ]; then + echo "$PROFILEDIR/${profile}-ora.conf"; return + elif [ -f "$dir/${profile}-ora.conf" ]; then + echo "$dir/${profile}-ora.conf"; return + fi + fi fi + echo "$dir/ora.conf" } function oracle_source_adminconf() { local dir="$1" @@ -717,6 +740,8 @@ function oracle_user_update() { MODE=auto PROFILEDIR=/etc/sqlmig +prod_PROFILE_MODE=prod +test_PROFILE_MODE=devel set_defaults sqlmig admindefaults=