sqlmig: l'option -f supporte plusieurs fichiers

This commit is contained in:
Jephté Clain 2018-06-04 14:26:29 +04:00
parent e78ec7f61c
commit 827dd141b7
1 changed files with 53 additions and 49 deletions

102
sqlmig
View File

@ -507,8 +507,8 @@ function mysql_set_mysqlargs() {
}
MYSQL_ADMIN_CONF_DONE=
function mysql_admin_update() {
local name="$1" update="$2" updatefile="$3" done
if [ -z "$updatefile" ]; then
local name="$1" update="$2" updateone="$3" done
if [ -z "$updateone" ]; then
if [ -z "$MYSQL_ADMIN_CONF_DONE" ]; then
MYSQL_ADMIN_CONF_DONE=1
mysql_tbconf
@ -522,17 +522,17 @@ function mysql_admin_update() {
estep "$name"
[ -n "$fake" ] && return
if [ -z "$updatefile" ]; then
if [ -z "$updateone" ]; then
mysql_before_update || die
fi
cat "$update" | mysql_admin_ve || abort_on_error
if [ -z "$updatefile" ]; then
if [ -z "$updateone" ]; then
mysql_after_update || die
fi
}
function mysql_user_update() {
local name="$1" update="$2" dbname="$3" updatefile="$4" done
if [ -z "$updatefile" ]; then
local name="$1" update="$2" dbname="$3" updateone="$4" done
if [ -z "$updateone" ]; then
if ! setx done=mysql_get_done "$name" "$dbname"; then
[ -n "$fake" ] || die
fi
@ -542,11 +542,11 @@ function mysql_user_update() {
estep "$name"
[ -n "$fake" ] && return
if [ -z "$updatefile" ]; then
if [ -z "$updateone" ]; then
mysql_before_update "$dbname" || die
fi
cat "$update" | mysql_user_ve || abort_on_error
if [ -z "$updatefile" ]; then
if [ -z "$updateone" ]; then
mysql_after_update "$dbname" || die
fi
}
@ -842,8 +842,8 @@ function oracle_source_userconf() {
}
ORACLE_ADMIN_CONF_DONE=
function oracle_admin_update() {
local name="$1" update="$2" updatefile="$3" done
if [ -z "$updatefile" ]; then
local name="$1" update="$2" updateone="$3" done
if [ -z "$updateone" ]; then
if [ -z "$ORACLE_ADMIN_CONF_DONE" ]; then
ORACLE_ADMIN_CONF_DONE=
oracle_tbconf
@ -855,17 +855,17 @@ function oracle_admin_update() {
estep "$name"
[ -n "$fake" ] && return
if [ -z "$updatefile" ]; then
if [ -z "$updateone" ]; then
oracle_before_update || die
fi
cat "$update" | oracle_admin_ve || abort_on_error
if [ -z "$updatefile" ]; then
if [ -z "$updateone" ]; then
oracle_after_update || die
fi
}
function oracle_user_update() {
local name="$1" update="$2" dbname="$3" updatefile="$4" done
if [ -z "$updatefile" ]; then
local name="$1" update="$2" dbname="$3" updateone="$4" done
if [ -z "$updateone" ]; then
setx done=oracle_get_done "$name" "$dbname" || die
[ -n "$done" ] && return
fi
@ -873,11 +873,11 @@ function oracle_user_update() {
estep "$name"
[ -n "$fake" ] && return
if [ -z "$updatefile" ]; then
if [ -z "$updateone" ]; then
oracle_before_update "$dbname" || die
fi
cat "$update" | oracle_user_ve || abort_on_error
if [ -z "$updatefile" ]; then
if [ -z "$updateone" ]; then
oracle_after_update "$dbname" || die
fi
}
@ -910,7 +910,7 @@ updatedir=
exportdir=
dbdir=
dbname=
updatefile=
updateone=
force=
data_csv=auto
mode="$MODE"
@ -945,7 +945,7 @@ args=(
-t:,--updatedir: updatedir=
-d:,--databasedir: dbdir=
-b:,--database: dbname=
-f:,--update-one: updatefile=
-f,--update-one updateone=1
-n,--fake fake=1
--force,--continue-on-error force=1
--no-data-csv data_csv=
@ -1187,7 +1187,27 @@ fi
# update
set_dbdirs
[ -n "$updatefile" ] && setx updatefile=abspath "$updatefile"
if [ -n "$updateone" ]; then
updatefiles=()
for updatefile in "$@"; do
array_add updatefiles "$(abspath "$updatefile")"
done
fi
function should_update() {
local update="$1" name
if [ -n "$updateone" ]; then
array_contains updatefiles "$update"
return $?
else
setx name=basename "$update"
if [ "$dbmode" != devel -a "${name%.devel.sql}" != "$name" ]; then
# si on est en mode autre que devel, le nom ne doit pas se terminer
# par .devel.sql
return 1
fi
return 0
fi
}
# répertoire temporaire pour Oracle
OPDIR=
@ -1206,11 +1226,8 @@ if [ -n "$updatedir" ]; then
# Mises à jour
etitled "Mises à jour admin"
for update in "${updates[@]}"; do
setx name=basename "$update"
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
name="${update#$updatedir/}"
mysql_admin_update "$name" "$update" "$updatefile"
should_update "$update" || continue
mysql_admin_update "${update#$updatedir/}" "$update" "$updateone"
done
eend; eclearp
@ -1222,11 +1239,8 @@ if [ -n "$updatedir" ]; then
# Mises à jour
etitled "Mises à jour"
for update in "${updates[@]}"; do
setx name=basename "$update"
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
name="${update#$updatedir/}"
oracle_admin_update "$name" "$update" "$updatefile"
should_update "$update" || continue
oracle_admin_update "${update#$updatedir/}" "$update" "$updateone"
done
eend; eclearp
fi
@ -1309,9 +1323,8 @@ for dbdir in "${dbdirs[@]}"; do
eend; continue
fi
for drop in "${drops[@]}"; do
should_update "$update" || continue
setx name=basename "$drop"
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
estep "$name"
[ -n "$fake" ] && continue
@ -1325,9 +1338,8 @@ for dbdir in "${dbdirs[@]}"; do
if ! mysql_admin_qe "select 1" "$dbname"; then
etitled "Création"
for create in "${creates[@]}"; do
should_update "$update" || continue
setx name=basename "$create"
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
estep "$name"
[ -n "$fake" ] && continue
@ -1341,15 +1353,12 @@ for dbdir in "${dbdirs[@]}"; do
etitled "Mises à jour"
mysql_tbconf "$dbname"
for update in "${updates[@]}"; do
setx name=basename "$update"
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
should_update "$update" || continue
if have_tag admin "$update"; then
[ -n "$updatedir" ] && name="${update#$updatedir/}" || name="${update#$dbdir/}"
mysql_admin_update "$name" "$update" "$updatefile"
mysql_admin_update "$name" "$update" "$updateone"
else
name="${update#$dbdir/}"
mysql_user_update "$name" "$update" "$dbname" "$updatefile"
mysql_user_update "${update#$dbdir/}" "$update" "$dbname" "$updateone"
fi
done
eend; eclearp
@ -1376,9 +1385,8 @@ for dbdir in "${dbdirs[@]}"; do
eend; continue
fi
for drop in "${drops[@]}"; do
should_update "$update" || continue
setx name=basename "$drop"
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
estep "$name"
[ -n "$fake" ] && continue
@ -1392,9 +1400,8 @@ for dbdir in "${dbdirs[@]}"; do
if ! oracle_admin_have_user "$dbname"; then
etitled "Création"
for create in "${creates[@]}"; do
should_update "$update" || continue
setx name=basename "$create"
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
estep "$name"
[ -n "$fake" ] && continue
@ -1408,15 +1415,12 @@ for dbdir in "${dbdirs[@]}"; do
etitled "Mises à jour"
oracle_tbconf "$dbname"
for update in "${updates[@]}"; do
setx name=basename "$update"
[ "$dbmode" == devel -o "${name%.devel.sql}" == "$name" ] || continue
[ -z "$updatefile" -o "$updatefile" == "$update" ] || continue
should_update "$update" || continue
if have_tag admin "$update"; then
[ -n "$updatedir" ] && name="${update#$updatedir/}" || name="${update#$dbdir/}"
oracle_admin_update "$name" "$update" "$updatefile"
oracle_admin_update "$name" "$update" "$updateone"
else
name="${update#$dbdir/}"
oracle_user_update "$name" "$update" "$dbname" "$updatefile"
oracle_user_update "${update#$dbdir/}" "$update" "$dbname" "$updateone"
fi
done
eend; eclearp