#!/bin/bash



dbuser=cosmic
dbpwd='Cosmic@2020'


###
if [ $# -ne 1 ]; then
    echo "Missing script argument"
    echo "usage: $(basename $0) [ierp-version]"
    exit 1
fi
ierpver=$1

echo "generate mc model sql srcipt,please wait a while......"

echo "clear mc data"
mysql -u${dbuser} -p${dbpwd} -h172.20.110.204 --socket=/tmp/mysql_3306.sock --port=3306  <<EOF
use mc;
delete from t_log_app;
delete from t_log_app_l;
delete from t_mc_logging_event;
delete from t_mc_logging_event_exception;
delete from t_mc_logging_event_property;
delete from t_mc_updatacenterlog;
delete from t_mc_upgradestatus;
update t_mc_envversions set fversion ='$ierpver';
EOF
echo "export mc sql srcipt..."
mysqldump -u${dbuser} -p${dbpwd} -h172.20.110.204 --socket=/tmp/mysql_3306.sock  --port=3306 -R --set-gtid-purged=OFF --skip-add-locks mc >mc.sql

echo "zip mc sql"
sed  -i "s/\(DEFINER=\)\(.*\)\`%\`//g"  mc.sql
rm -rf mc.zip
zip -r  mc.zip mc.sql

echo "success!"
