sqlmig: ajout de l'option --update-one
This commit is contained in:
parent
6a6b2a5f32
commit
7181725056
114
sqlmig
114
sqlmig
|
@ -98,7 +98,7 @@ OPTIONS
|
|||
-e, --export DESTUPDATEDIR
|
||||
Exporter les définitions de bases de données et mises à jour du
|
||||
répertoire courant vers le répertoire DESTUPDATEDIR
|
||||
-u, --update
|
||||
-u, --update-all
|
||||
Mettre à jour la base de données. C'est l'option par défaut
|
||||
-t, --updatedir UPDATEDIR
|
||||
Spécifier le répertoire qui contient les répertoires de mises à jour
|
||||
|
@ -114,6 +114,10 @@ OPTIONS
|
|||
données est calculé à partir du nom du répertoire DATABASEDIR. Cette
|
||||
option peut être utilisée par exemple pour créer une base de test à
|
||||
partir des définitions d'une base de prod.
|
||||
-f, --update-one UPDATE
|
||||
Forcer l'application de la mise à jour spécifiée. Ne pas mettre à jour
|
||||
l'état des mises à jour installées. Avec cette option, tout se passe
|
||||
comme si le seul fichier existant est celui spécifié.
|
||||
|
||||
-n, --fake
|
||||
Ne pas faire les mises à jour, afficher simplement ce qui serait fait
|
||||
|
@ -421,36 +425,48 @@ function mysql_set_mysqlargs() {
|
|||
}
|
||||
MYSQL_ADMIN_CONF_DONE=
|
||||
function mysql_admin_update() {
|
||||
local name="$1" update="$2" done
|
||||
if [ -z "$MYSQL_ADMIN_CONF_DONE" ]; then
|
||||
MYSQL_ADMIN_CONF_DONE=1
|
||||
mysql_tbconf
|
||||
local name="$1" update="$2" updatefile="$3" done
|
||||
if [ -z "$updatefile" ]; then
|
||||
if [ -z "$MYSQL_ADMIN_CONF_DONE" ]; then
|
||||
MYSQL_ADMIN_CONF_DONE=1
|
||||
mysql_tbconf
|
||||
fi
|
||||
if ! setx done=mysql_get_done "$name"; then
|
||||
[ -n "$fake" ] || die
|
||||
fi
|
||||
[ -n "$done" ] && return
|
||||
fi
|
||||
if ! setx done=mysql_get_done "$name"; then
|
||||
[ -n "$fake" ] || die
|
||||
fi
|
||||
[ -n "$done" ] && return
|
||||
|
||||
estep "$name"
|
||||
[ -n "$fake" ] && return
|
||||
|
||||
mysql_before_update || die
|
||||
if [ -z "$updatefile" ]; then
|
||||
mysql_before_update || die
|
||||
fi
|
||||
cat "$update" | mysql_admin_ve || abort_on_error
|
||||
mysql_after_update || die
|
||||
if [ -z "$updatefile" ]; then
|
||||
mysql_after_update || die
|
||||
fi
|
||||
}
|
||||
function mysql_user_update() {
|
||||
local name="$1" update="$2" dbname="$3" done
|
||||
if ! setx done=mysql_get_done "$name" "$dbname"; then
|
||||
[ -n "$fake" ] || die
|
||||
local name="$1" update="$2" dbname="$3" updatefile="$4" done
|
||||
if [ -z "$updatefile" ]; then
|
||||
if ! setx done=mysql_get_done "$name" "$dbname"; then
|
||||
[ -n "$fake" ] || die
|
||||
fi
|
||||
[ -n "$done" ] && return
|
||||
fi
|
||||
[ -n "$done" ] && return
|
||||
|
||||
estep "$name"
|
||||
[ -n "$fake" ] && return
|
||||
|
||||
mysql_before_update "$dbname" || die
|
||||
if [ -z "$updatefile" ]; then
|
||||
mysql_before_update "$dbname" || die
|
||||
fi
|
||||
cat "$update" | mysql_user_ve || abort_on_error
|
||||
mysql_after_update "$dbname" || die
|
||||
if [ -z "$updatefile" ]; then
|
||||
mysql_after_update "$dbname" || die
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
@ -739,32 +755,44 @@ function oracle_source_userconf() {
|
|||
}
|
||||
ORACLE_ADMIN_CONF_DONE=
|
||||
function oracle_admin_update() {
|
||||
local name="$1" update="$2" done
|
||||
if [ -z "$ORACLE_ADMIN_CONF_DONE" ]; then
|
||||
ORACLE_ADMIN_CONF_DONE=
|
||||
oracle_tbconf
|
||||
local name="$1" update="$2" updatefile="$3" done
|
||||
if [ -z "$updatefile" ]; then
|
||||
if [ -z "$ORACLE_ADMIN_CONF_DONE" ]; then
|
||||
ORACLE_ADMIN_CONF_DONE=
|
||||
oracle_tbconf
|
||||
fi
|
||||
setx done=oracle_get_done "$name" || die
|
||||
[ -n "$done" ] && return
|
||||
fi
|
||||
setx done=oracle_get_done "$name" || die
|
||||
[ -n "$done" ] && return
|
||||
|
||||
estep "$name"
|
||||
[ -n "$fake" ] && return
|
||||
|
||||
oracle_before_update || die
|
||||
if [ -z "$updatefile" ]; then
|
||||
oracle_before_update || die
|
||||
fi
|
||||
cat "$update" | oracle_admin_ve || abort_on_error
|
||||
oracle_after_update || die
|
||||
if [ -z "$updatefile" ]; then
|
||||
oracle_after_update || die
|
||||
fi
|
||||
}
|
||||
function oracle_user_update() {
|
||||
local name="$1" update="$2" dbname="$3" done
|
||||
setx done=oracle_get_done "$name" "$dbname" || die
|
||||
[ -n "$done" ] && return
|
||||
local name="$1" update="$2" dbname="$3" updatefile="$4" done
|
||||
if [ -z "$updatefile" ]; then
|
||||
setx done=oracle_get_done "$name" "$dbname" || die
|
||||
[ -n "$done" ] && return
|
||||
fi
|
||||
|
||||
estep "$name"
|
||||
[ -n "$fake" ] && return
|
||||
|
||||
oracle_before_update "$dbname" || die
|
||||
if [ -z "$updatefile" ]; then
|
||||
oracle_before_update "$dbname" || die
|
||||
fi
|
||||
cat "$update" | oracle_user_ve || abort_on_error
|
||||
oracle_after_update "$dbname" || die
|
||||
if [ -z "$updatefile" ]; then
|
||||
oracle_after_update "$dbname" || die
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
@ -793,6 +821,7 @@ updatedir=
|
|||
exportdir=
|
||||
dbdir=
|
||||
dbname=
|
||||
updatefile=
|
||||
force=
|
||||
data_csv=auto
|
||||
mode="$MODE"
|
||||
|
@ -818,10 +847,11 @@ args=(
|
|||
--oracle type=oracle
|
||||
-0,--init action=init
|
||||
-e:,--export: '$action=export; set@ exportdir'
|
||||
-u,--update action=update
|
||||
-u,--update-all action=update
|
||||
-t:,--updatedir: updatedir=
|
||||
-d:,--databasedir: dbdir=
|
||||
-b:,--database: dbname=
|
||||
-f:,--update-one: updatefile=
|
||||
-n,--fake fake=1
|
||||
--force,--continue-on-error force=1
|
||||
--no-data-csv data_csv=
|
||||
|
@ -1028,6 +1058,8 @@ if [ -n "$dbname" -a ${#dbdirs[*]} -gt 1 ]; then
|
|||
die "Avec l'option -n, une seule base de données doit être spécifiée"
|
||||
fi
|
||||
|
||||
[ -n "$updatefile" ] && setx updatefile=abspath "$updatefile"
|
||||
|
||||
# répertoire temporaire pour Oracle
|
||||
OPDIR=
|
||||
|
||||
|
@ -1047,7 +1079,8 @@ if [ -n "$updatedir" ]; then
|
|||
for update in "${updates[@]}"; do
|
||||
setx name=basename "$update"
|
||||
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
|
||||
mysql_admin_update "$name" "$update"
|
||||
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
|
||||
mysql_admin_update "$name" "$update" "$updatefile"
|
||||
done
|
||||
eend; eclearp
|
||||
|
||||
|
@ -1061,7 +1094,8 @@ if [ -n "$updatedir" ]; then
|
|||
for update in "${updates[@]}"; do
|
||||
setx name=basename "$update"
|
||||
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
|
||||
oracle_admin_update "$name" "$update"
|
||||
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
|
||||
oracle_admin_update "$name" "$update" "$updatefile"
|
||||
done
|
||||
eend; eclearp
|
||||
fi
|
||||
|
@ -1139,6 +1173,7 @@ for dbdir in "${dbdirs[@]}"; do
|
|||
for drop in "${drops[@]}"; do
|
||||
setx name=basename "$drop"
|
||||
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
|
||||
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
|
||||
estep "$name"
|
||||
[ -n "$fake" ] && continue
|
||||
|
||||
|
@ -1154,6 +1189,7 @@ for dbdir in "${dbdirs[@]}"; do
|
|||
for create in "${creates[@]}"; do
|
||||
setx name=basename "$create"
|
||||
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
|
||||
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
|
||||
estep "$name"
|
||||
[ -n "$fake" ] && continue
|
||||
|
||||
|
@ -1169,10 +1205,11 @@ for dbdir in "${dbdirs[@]}"; do
|
|||
for update in "${updates[@]}"; do
|
||||
setx name=basename "$update"
|
||||
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
|
||||
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
|
||||
if have_tag admin "$update"; then
|
||||
mysql_admin_update "$name" "$update"
|
||||
mysql_admin_update "$name" "$update" "$updatefile"
|
||||
else
|
||||
mysql_user_update "$name" "$update" "$dbname"
|
||||
mysql_user_update "$name" "$update" "$dbname" "$updatefile"
|
||||
fi
|
||||
done
|
||||
eend; eclearp
|
||||
|
@ -1196,6 +1233,7 @@ for dbdir in "${dbdirs[@]}"; do
|
|||
for drop in "${drops[@]}"; do
|
||||
setx name=basename "$drop"
|
||||
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
|
||||
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
|
||||
estep "$name"
|
||||
[ -n "$fake" ] && continue
|
||||
|
||||
|
@ -1211,6 +1249,7 @@ for dbdir in "${dbdirs[@]}"; do
|
|||
for create in "${creates[@]}"; do
|
||||
setx name=basename "$create"
|
||||
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
|
||||
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
|
||||
estep "$name"
|
||||
[ -n "$fake" ] && continue
|
||||
|
||||
|
@ -1226,10 +1265,11 @@ for dbdir in "${dbdirs[@]}"; do
|
|||
for update in "${updates[@]}"; do
|
||||
setx name=basename "$update"
|
||||
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
|
||||
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
|
||||
if have_tag admin "$update"; then
|
||||
oracle_admin_update "$name" "$update"
|
||||
oracle_admin_update "$name" "$update" "$updatefile"
|
||||
else
|
||||
oracle_user_update "$name" "$update" "$dbname"
|
||||
oracle_user_update "$name" "$update" "$dbname" "$updatefile"
|
||||
fi
|
||||
done
|
||||
eend; eclearp
|
||||
|
|
Loading…
Reference in New Issue