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