Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ install/logging/logstash-*.zip
# JaCoCo Reports
/target
/jacoco-reports
/test-screenshots
/test-screenshots

*.cnf
6 changes: 5 additions & 1 deletion create_server_dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ print 'Removing previous distribution directory...'
rm -rf ${DIST}

print 'Creating new CWS distribution directory...'
mkdir -p ${CWS}/{bpmn,config/templates,installer,logs,sql/cws}
mkdir -p ${CWS}/{bpmn,config/templates,installer,logs,upgrade,sql/cws}

print 'Unzipping Camunda into distribution...'
unzip ${INSTALL_DIR}/cws_camunda-bpm-tomcat-${CAMUNDA_VER}.zip -x start-camunda.bat start-camunda.sh -d ${CWS} > ${CWS}/logs/camunda_extract.log 2>&1
Expand Down Expand Up @@ -219,6 +219,10 @@ cp ${INSTALL_DIR}/launch_ls.sh ${CWS}
print 'Copying Modeller scripts and libraries...'
cp -R ${INSTALL_DIR}/modeler ${CWS}

print 'Copying Upgrade scripts...'
cp -R ${INSTALL_DIR}/upgrade/upgrade_to_2.4.sh ${CWS}/upgrade
cp -R ${INSTALL_DIR}/upgrade/README.md ${CWS}/upgrade

print 'Installing context.xml to Tomcat...'
cp ${INSTALL_DIR}/context.xml ${CWS_TOMCAT_ROOT}/conf/context.xml

Expand Down
24 changes: 24 additions & 0 deletions install/upgrade/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CWS v2.4 Database Upgrade

### Use this script before installing CWS v2.4 to update your database schema.

#### _NOTICE: Once you've used this upgrade script, preserve your existing data by answering 'No' to the cws installation prompted: Do you want this script to drop and re-create the database for you, so that you have a clean install?_

This upgrade helps to prepare the database of older CWS versions, previous to v2.4, to be used for new installations of CWS v2.4. The script updates the existing database schema to match CWS v2.4 core. This gives the user the option of preserving data and migrating to CWS v2.4 without blowing up the database.

### Update Actions:

* *Script updates to database* :
* Alter database table *cws_worker* to add new column `max_num_running_procs`
* Remove existing worker data from tables `cws_worker`, `cws_worker_proc_def`, `cws_log_usage`

To run the commands:


```
cd install/upgrade/
```

```
./upgrade_to_2.4.sh
```
105 changes: 105 additions & 0 deletions install/upgrade/upgrade_to_2.4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
# -------------------
# upgrade_to_2.4.sh
# -------------------
# Update previous version of CWS database schema to CWS v2.4 core schema
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

read -p "Would you like to upgrade the CWS database schema to CWS v2.4? (Y/N): " UPGRADE_DB
while [[ ! ${UPGRADE_DB} =~ $(echo "^(y|Y|n|N)$") ]]; do
echo " ERROR: Must specify either 'Y' or 'N'.";
read -p "Continue? (Y/N): " UPGRADE_DB
done

if [[ ${UPGRADE_DB} =~ $(echo "^(y|Y)$") ]]
then
echo " "
echo "[Enter Your Database Configuration]"
read -p 'DB Host: ' DB_HOST
read -p 'DB Name: ' DB_NAME
read -p 'DB Port: ' DB_PORT
read -p 'DB Username: ' DB_USERNAME
read -sp 'DB Password: ' DB_PASSWORD
echo " "
echo " "
echo "Your database Configuration is:"
echo " DB HOST: ${DB_HOST}"
echo " DB NAME: ${DB_NAME}"
echo " DB PORT: ${DB_PORT}"
echo " DB USERNAME: ${DB_USERNAME}"
echo " DB PASSWORD: [PASSWORD]"
echo " "

while [[ ! ${CREDS_DB} =~ $(echo "^(y|Y|n|N)$") ]]; do
read -p "Do you want to continue with the database upgrade? (specify either 'Y' or 'N'): " CREDS_DB
done
fi

if [[ ${CREDS_DB} =~ $(echo "^(y|Y)$") ]]
then
echo " "
echo "[mysql]" > ${ROOT}/myupgrade.cnf
echo "host=${DB_HOST}" >> ${ROOT}/myupgrade.cnf
echo "user=\"${DB_USERNAME}\"" >> ${ROOT}/myupgrade.cnf
echo "password=\"${DB_PASSWORD}\"" >> ${ROOT}/myupgrade.cnf
echo "port=\"${DB_PORT}\"" >> ${ROOT}/myupgrade.cnf
chmod 644 ${ROOT}/myupgrade.cnf

echo "Checking number of CORES on machine..."

if [[ "$OSTYPE" =~ ^darwin ]]; then
CORE_NUMBER=`sysctl -n hw.ncpu`
echo " CORE: " ${CORE_NUMBER}
fi
if [[ "$OSTYPE" =~ ^linux ]]; then
CORE_NUMBER_=`lscpu -b -p=Core,Socket | grep -v '^#' | sort -u | wc -l`
echo " CORE: " ${CORE_NUMBER}
fi

echo "Checking whether database ${DB_NAME} already exists..."
RES=`mysql --defaults-file=${ROOT}/myupgrade.cnf -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${DB_NAME}'"`

if [[ $? -gt 0 ]]; then
echo "ERROR: Problem checking for database. "
echo " Please check your database configuration, and try again."
rm -f ${ROOT}/myupgrade.cnf
rm -rf ${ROOT}/upgrade_core_db.sql
exit 1
fi

FOUND=`echo $RES | grep ${DB_NAME} | wc -l`

if [[ ${FOUND} -eq 1 ]]; then
echo " Database ${DB_NAME} exists."
echo " "
echo "Updating tables in CWS CORE DB..."

cat > ${ROOT}/upgrade_core_db.sql <<- EOF
DELETE FROM cws_log_usage;
DELETE FROM cws_worker_proc_def;
DELETE FROM cws_worker;
ALTER TABLE cws_worker ADD max_num_running_procs int(11) DEFAULT ${CORE_NUMBER} AFTER job_executor_max_pool_size;
EOF

mysql --defaults-file=${ROOT}/myupgrade.cnf ${DB_NAME} < ${ROOT}/upgrade_core_db.sql

if [[ $? -gt 0 ]]; then
echo "ERROR: Problem updating tables. Database Column may already exist."
echo " Please check your database upgrade sql template '${ROOT}/upgrade_core_db.sql', and try again."
cat ${ROOT}/upgrade_core_db.sql
cat ${ROOT}/myupgrade.cnf
rm -rf ${ROOT}/myupgrade.cnf
rm -rf ${ROOT}/upgrade_core_db.sql
exit 1
fi
rm -rf ${ROOT}/myupgrade.cnf
rm -rf ${ROOT}/upgrade_core_db.sql
echo " Upgrade to CWS Database was made."
else
echo " Database ${DB_NAME} DOES NOT exists. Please check your database configuration"
fi
else
echo " Upgrade to CWS Database was NOT made."
rm -rf ${ROOT}/myupgrade.cnf
rm -rf ${ROOT}/upgrade_core_db.sql
fi