mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
https://gitlab.chatopera.com/chatopera/cosinee/issues/772 enable mysql upgrade script
This commit is contained in:
parent
919146c3fb
commit
4b66f58c42
@ -39,9 +39,7 @@ RUN /bin/bash -c "mkdir -p /{data,logs}"
|
||||
# build WAR
|
||||
RUN mkdir -p /opt/chatopera
|
||||
COPY ./app/target/contact-center-*.war /opt/chatopera/contact-center.war
|
||||
COPY ./assets/setup-mysql-db.sh /opt/chatopera
|
||||
COPY ./assets/utils.sh /opt/chatopera
|
||||
COPY ./assets/docker-entrypoint.sh /opt/chatopera
|
||||
COPY ./assets/*.sh /opt/chatopera
|
||||
RUN chmod +x /opt/chatopera/*.sh
|
||||
|
||||
WORKDIR /opt/chatopera
|
||||
|
@ -434,7 +434,7 @@
|
||||
<resource>
|
||||
<directory>../config/sql/</directory>
|
||||
<includes>
|
||||
<include>cosinee-MySQL-slim.sql</include>
|
||||
<include>**/*.sql</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</webResources>
|
||||
|
@ -11,7 +11,8 @@ baseDir=$(cd `dirname "$0"`;pwd)
|
||||
# main
|
||||
[ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return
|
||||
cd $baseDir
|
||||
./setup-mysql-db.sh
|
||||
./mysql.setup.db.sh
|
||||
./mysql.upgrade.db.sh
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
java -jar contact-center.war
|
||||
|
@ -12,7 +12,7 @@ CONTACT_CENTER_DB=`parse_dbname ${SPRING_DATASOURCE_URL}`
|
||||
CONTACT_CENTER_WAR=/opt/chatopera/contact-center.war
|
||||
MYSQL_SCRIPT_NAME=cosinee-MySQL-slim.sql
|
||||
|
||||
println "connecting to $MYSQL_WRITEMODE_IP:$MYSQL_WRITEMODE_PORT/$CONTACT_CENTER_DB with $SPRING_DATASOURCE_USERNAME/****"
|
||||
println "[setup] connecting to $MYSQL_WRITEMODE_IP:$MYSQL_WRITEMODE_PORT/$CONTACT_CENTER_DB with $SPRING_DATASOURCE_USERNAME/****"
|
||||
|
||||
# functions
|
||||
function import_db(){
|
77
contact-center/assets/mysql.upgrade.db.sh
Executable file
77
contact-center/assets/mysql.upgrade.db.sh
Executable file
@ -0,0 +1,77 @@
|
||||
#! /bin/bash
|
||||
###########################################
|
||||
#
|
||||
###########################################
|
||||
|
||||
# constants
|
||||
baseDir=$(cd `dirname "$0"`;pwd)
|
||||
source $baseDir/utils.sh
|
||||
MYSQL_WRITEMODE_IP=`parse_host ${SPRING_DATASOURCE_URL}`
|
||||
MYSQL_WRITEMODE_PORT=`parse_port ${SPRING_DATASOURCE_URL}`
|
||||
CONTACT_CENTER_DB=`parse_dbname ${SPRING_DATASOURCE_URL}`
|
||||
CONTACT_CENTER_WAR=/opt/chatopera/contact-center.war
|
||||
UPGRADE_DB_SCRIPT_DIR=/tmp/ROOT/upgrade
|
||||
|
||||
println "[upgrade] connecting to $MYSQL_WRITEMODE_IP:$MYSQL_WRITEMODE_PORT/$CONTACT_CENTER_DB with $SPRING_DATASOURCE_USERNAME/****"
|
||||
|
||||
# functions
|
||||
function upgrade_db(){
|
||||
if [ ! -f $1 ]; then exit 1; fi
|
||||
println "run MySQL DB upgrade script" $1 "..."
|
||||
mysql -u ${SPRING_DATASOURCE_USERNAME} \
|
||||
-h ${MYSQL_WRITEMODE_IP} \
|
||||
-P ${MYSQL_WRITEMODE_PORT} -p${SPRING_DATASOURCE_PASSWORD} \
|
||||
< $1
|
||||
|
||||
# verify status
|
||||
if [ ! $? -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function extract_war(){
|
||||
println "extract SQL script ..."
|
||||
if [ -f $CONTACT_CENTER_WAR ]; then
|
||||
cd /tmp
|
||||
if [ -d ROOT ]; then
|
||||
rm -rf ROOT
|
||||
fi
|
||||
|
||||
unzip -q $CONTACT_CENTER_WAR -d ROOT
|
||||
if [ -f /tmp/ROOT/$MYSQL_SCRIPT_NAME ]; then
|
||||
println "start to import database ..."
|
||||
import_db /tmp/ROOT/$MYSQL_SCRIPT_NAME
|
||||
# verify status
|
||||
if [ ! $? -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
rm -rf /tmp/ROOT
|
||||
else
|
||||
println "SQL script not exist."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
println "War file not exist."
|
||||
fi
|
||||
}
|
||||
|
||||
# main
|
||||
[ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return
|
||||
|
||||
## check root dir
|
||||
if [ ! -d /tmp/ROOT ]; then
|
||||
extract_war
|
||||
fi
|
||||
|
||||
## run scripts
|
||||
if [ -d $UPGRADE_DB_SCRIPT_DIR ]; then
|
||||
cd $UPGRADE_DB_SCRIPT_DIR
|
||||
for x in `find . -name "*.sql"|sort`; do
|
||||
echo "[run] " $x " ..."
|
||||
upgrade_db $x
|
||||
if [ ! $? -eq 0 ]; then
|
||||
echo "Failed result with" $x
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
@ -0,0 +1,3 @@
|
||||
-- Enable whitelist for online users
|
||||
USE `cosinee`;
|
||||
ALTER TABLE uk_consult_invite add whitelist_mode tinyint(4) DEFAULT '0' COMMENT '启用白名单';
|
Loading…
x
Reference in New Issue
Block a user