Reset database tables on update (#351)

* Reset database tables on update

* Add changes

* Add changes

* Add changes

* Add changes

* Add changes

* Add changes
This commit is contained in:
Roman Demidov 2021-04-14 17:10:38 +03:00 committed by GitHub
parent 30c5612cfb
commit f2c708cff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,16 +11,32 @@ shopt -s globstar
APP_DIR="/var/www/${COMPANY_NAME}/documentserver" APP_DIR="/var/www/${COMPANY_NAME}/documentserver"
DATA_DIR="/var/www/${COMPANY_NAME}/Data" DATA_DIR="/var/www/${COMPANY_NAME}/Data"
PRIVATE_DATA_DIR="${DATA_DIR}/.private"
DS_RELEASE_DATE="${PRIVATE_DATA_DIR}/ds_release_date"
LOG_DIR="/var/log/${COMPANY_NAME}" LOG_DIR="/var/log/${COMPANY_NAME}"
DS_LOG_DIR="${LOG_DIR}/documentserver" DS_LOG_DIR="${LOG_DIR}/documentserver"
LIB_DIR="/var/lib/${COMPANY_NAME}" LIB_DIR="/var/lib/${COMPANY_NAME}"
DS_LIB_DIR="${LIB_DIR}/documentserver" DS_LIB_DIR="${LIB_DIR}/documentserver"
CONF_DIR="/etc/${COMPANY_NAME}/documentserver" CONF_DIR="/etc/${COMPANY_NAME}/documentserver"
IS_UPGRADE="false"
ONLYOFFICE_DATA_CONTAINER=${ONLYOFFICE_DATA_CONTAINER:-false} ONLYOFFICE_DATA_CONTAINER=${ONLYOFFICE_DATA_CONTAINER:-false}
ONLYOFFICE_DATA_CONTAINER_HOST=${ONLYOFFICE_DATA_CONTAINER_HOST:-localhost} ONLYOFFICE_DATA_CONTAINER_HOST=${ONLYOFFICE_DATA_CONTAINER_HOST:-localhost}
ONLYOFFICE_DATA_CONTAINER_PORT=80 ONLYOFFICE_DATA_CONTAINER_PORT=80
RELEASE_DATE="$(stat -c="%y" ${APP_DIR}/server/DocService/docservice | sed -r 's/=([0-9]+)-([0-9]+)-([0-9]+) ([0-9:.+ ]+)/\1-\2-\3/')";
if [ -f ${DS_RELEASE_DATE} ]; then
PREV_RELEASE_DATE=$(head -n 1 ${DS_RELEASE_DATE})
else
PREV_RELEASE_DATE="0"
fi
if [ "${RELEASE_DATE}" != "${PREV_RELEASE_DATE}" ]; then
if [ ${ONLYOFFICE_DATA_CONTAINER} != "true" ]; then
IS_UPGRADE="true";
fi
fi
SSL_CERTIFICATES_DIR="${DATA_DIR}/certs" SSL_CERTIFICATES_DIR="${DATA_DIR}/certs"
if [[ -z $SSL_CERTIFICATE_PATH ]] && [[ -f ${SSL_CERTIFICATES_DIR}/onlyoffice.crt ]]; then if [[ -z $SSL_CERTIFICATE_PATH ]] && [[ -f ${SSL_CERTIFICATES_DIR}/onlyoffice.crt ]]; then
SSL_CERTIFICATE_PATH=${SSL_CERTIFICATES_DIR}/onlyoffice.crt SSL_CERTIFICATE_PATH=${SSL_CERTIFICATES_DIR}/onlyoffice.crt
@ -327,6 +343,36 @@ create_db_tbl() {
esac esac
} }
upgrade_db_tbl() {
case $DB_TYPE in
"postgres")
upgrade_postgresql_tbl
;;
"mariadb"|"mysql")
upgrade_mysql_tbl
;;
esac
}
upgrade_postgresql_tbl() {
if [ -n "$DB_PWD" ]; then
export PGPASSWORD=$DB_PWD
fi
PSQL="psql -q -h$DB_HOST -p$DB_PORT -d$DB_NAME -U$DB_USER -w"
$PSQL -f "$APP_DIR/server/schema/postgresql/removetbl.sql"
$PSQL -f "$APP_DIR/server/schema/postgresql/createdb.sql"
}
upgrade_mysql_tbl() {
CONNECTION_PARAMS="-h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PWD -w"
MYSQL="mysql -q $CONNECTION_PARAMS"
$MYSQL $DB_NAME < "$APP_DIR/server/schema/mysql/removetbl.sql" >/dev/null 2>&1
$MYSQL $DB_NAME < "$APP_DIR/server/schema/mysql/createdb.sql" >/dev/null 2>&1
}
create_postgresql_tbl() { create_postgresql_tbl() {
if [ -n "$DB_PWD" ]; then if [ -n "$DB_PWD" ]; then
export PGPASSWORD=$DB_PWD export PGPASSWORD=$DB_PWD
@ -423,6 +469,11 @@ update_logrotate_settings(){
sed 's|\(^su\b\).*|\1 root root|' -i /etc/logrotate.conf sed 's|\(^su\b\).*|\1 root root|' -i /etc/logrotate.conf
} }
update_release_date(){
mkdir -p ${PRIVATE_DATA_DIR}
echo ${RELEASE_DATE} > ${DS_RELEASE_DATE}
}
# create base folders # create base folders
for i in converter docservice spellchecker metrics; do for i in converter docservice spellchecker metrics; do
mkdir -p "${DS_LOG_DIR}/$i" mkdir -p "${DS_LOG_DIR}/$i"
@ -527,6 +578,11 @@ if [ ${ONLYOFFICE_DATA_CONTAINER} != "true" ]; then
waiting_for_redis waiting_for_redis
fi fi
if [ "${IS_UPGRADE}" = "true" ]; then
upgrade_db_tbl
update_release_date
fi
update_nginx_settings update_nginx_settings
update_supervisor_settings update_supervisor_settings