Skip to content

Commit

Permalink
chore: SQL update script for v5.6.0
Browse files Browse the repository at this point in the history
Fixes #5491
  • Loading branch information
cgx committed Mar 25, 2022
1 parent c348ca2 commit 3e11e0a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Scripts/sql-update-5.5.1_to_5.6.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -euo pipefail

# This script only works with PostgreSQL and MySQL - it does:
#
# - increase the c_value column of sessions table to varchar(4096)

sessiontype=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSSessionsFolderURL =/ {print $2}' | awk -F: '{ print $1 }')

if [ -z "$sessiontype" ]; then
echo "Failed to obtain session table type" >&2
exit 1
fi

if [[ "$sessiontype" == "postgresql" ]]; then
sessionurl=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSSessionsFolderURL =/ {print $2}' | cut -d \/ -f1-4)
sessiontable=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSSessionsFolderURL =/ {print $2}' | awk -F/ '{print $NF}')
echo "Converting c_value from VARCHAR(255) to VARCHAR(4096) in sessions table ($sessiontable)"
psql $sessionurl -c "ALTER TABLE $sessiontable ALTER COLUMN c_value TYPE VARCHAR(4096);"
elif [[ "$sessiontype" == "mysql" ]]; then
sessiontable=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSSessionsFolderURL =/ {print $2}' | awk -F/ '{print $NF}')
mysqlargs=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSSessionsFolderURL =/ {print $2}' | sed 's/mysql:\/\/\([^:]\+\):\([^@]\+\)@\([^\:]\+\):\([^\/]\+\)\/\([^\/]\+\).\+/-h \3 -P \4 -u \1 -p\2 \5/')
echo "Converting c_value from VARCHAR(255) to VARCHAR(4096) in sessions table ($sessiontable)"
mysql -v $mysqlargs -e "ALTER TABLE $sessiontable MODIFY c_value VARCHAR(4096);"
else
echo "Unsupported database type $sessiontype"
exit 1
fi

exit 0

0 comments on commit 3e11e0a

Please sign in to comment.