Commit c9ffd6ff authored by BERJON Matthieu's avatar BERJON Matthieu

Add of the host argument to the command line

In order to satisfy the deployement on Docker, I added to the command
line the possibility to specify the host.
I took the opportunity to correct a bug as the migration file name
changed and wasn't updated into this script.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>
parent 43303f32
......@@ -2,7 +2,6 @@
#
USER=root
HOST=localhost
DB_SRC=allgo
DB_TGT=allgopy
TEMP_DIR=/tmp/sql
......@@ -16,14 +15,14 @@ DumpDb () {
mkdir -p $TEMP_DIR
for t in $TABLES
do
mysqldump -u $USER -h $HOST $DB_SRC $t > $TEMP_DIR/db_$t.sql
mysqldump -u $USER -h $1 $DB_SRC $t > $TEMP_DIR/db_$t.sql
done
}
LoadDb () {
# We have to first get all the tables (including the ones created by Django)
TABLES_TO_DROP=$(mysql -u $USER $DB_TGT -e 'SHOW TABLES;')
TABLES_TO_DROP=$(mysql -u $USER -h $1 $DB_TGT -e 'SHOW TABLES;')
TO_DROP=$(echo $TABLES_TO_DROP | awk '{for(i=2;i<=NF;i++)print $i}')
if [ ${#TO_DROP[@]} -gt 0 ]; then
......@@ -31,7 +30,7 @@ LoadDb () {
do
# We disable the foreign key constraint check in order to avoid dropping
# issues. We reactivate it just afterwards
mysql -u $USER -h $HOST $DB_TGT -e \
mysql -u $USER -h $1 $DB_TGT -e \
"SET FOREIGN_KEY_CHECKS = 0; DROP TABLE $TABLE; SET FOREIGN_KEY_CHECKS = 1;"
done
fi
......@@ -44,11 +43,11 @@ LoadDb () {
for TABLE in $TABLES
do
mysql -u $USER -h $HOST $DB_TGT < $TEMP_DIR/db_$TABLE.sql
mysql -u $USER -h $1 $DB_TGT < $TEMP_DIR/db_$TABLE.sql
done
# Apply the migration
mysql -u $USER -h $HOST $DB_TGT < tools/migration.sql
mysql -u $USER -h $1 $DB_TGT < tools/migration2django.sql
# Tell Django to use the current status of the database and start the migrations
# from that point
......@@ -61,30 +60,32 @@ Help() {
cat << EOF
Use: $0 [options]
Options:
-d, --dump Dump the tables of the allgo database into the sql folder
-i, --init Dump the tables of the allgo database, make the migration
and delete the dump (-d and -l at the same time)
-l, --load Load the tables into the allgopy database
-h, --help Show this help
-d, --dump HOST Dump the tables of the allgo database into the sql
folder
-i, --init HOST Dump the tables of the allgo database, make the
migration and delete the dump (-d and -l at the same
time)
-l, --load HOST Load the tables into the allgopy database
-h, --help Show this help
EOF
}
while getopts dilh OPTIONS
while getopts d:i:l:h OPTIONS
do
case $OPTIONS in
d | --dump)
DumpDb
DumpDb $OPTARG
;;
i | --init)
DumpDb
LoadDb
DumpDb $OPTARG
LoadDb $OPTARG
rm -rf $TEMP_DIR
;;
l | --load)
LoadDb
LoadDb $OPTARG
;;
h | --help)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment