2015-05-12 21:48:42 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
# This script only works with PostgreSQL
|
2015-05-13 16:45:19 +02:00
|
|
|
# updates c_partstates to text
|
|
|
|
# adds c_description to Calendar quick tables
|
2015-05-12 21:48:42 +02:00
|
|
|
# http://www.sogo.nu/bugs/view.php?id=3175
|
|
|
|
# the field length was actually changed in v2.2.18
|
|
|
|
|
|
|
|
defaultusername=$USER
|
|
|
|
defaulthostname=localhost
|
|
|
|
defaultdatabase=$USER
|
|
|
|
#indextable=sogo_folder_info
|
|
|
|
indextable=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSFolderInfoURL =/ {print $2}' | awk -F/ '{print $NF}')
|
|
|
|
if [ -z "$indextable" ]; then
|
|
|
|
echo "Couldn't fetch OCSFolderInfoURL value, aborting" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
read -p "Username ($defaultusername): " username
|
|
|
|
read -p "Hostname ($defaulthostname): " hostname
|
|
|
|
read -p "Database ($defaultdatabase): " database
|
|
|
|
|
|
|
|
if [ -z "$username" ]
|
|
|
|
then
|
|
|
|
username=$defaultusername
|
|
|
|
fi
|
|
|
|
if [ -z "$hostname" ]
|
|
|
|
then
|
|
|
|
hostname=$defaulthostname
|
|
|
|
fi
|
|
|
|
if [ -z "$database" ]
|
|
|
|
then
|
|
|
|
database=$defaultdatabase
|
|
|
|
fi
|
|
|
|
|
|
|
|
sqlscript=""
|
|
|
|
|
2015-05-13 16:45:19 +02:00
|
|
|
function adjustSchema() {
|
2015-05-12 21:48:42 +02:00
|
|
|
oldIFS="$IFS"
|
|
|
|
IFS=" "
|
2015-05-13 16:45:19 +02:00
|
|
|
part1="`echo -e \"ALTER TABLE $table ALTER COLUMN c_partstates TYPE TEXT;\\n\"`";
|
|
|
|
part2="`echo -e \"ALTER TABLE $table ADD COLUMN c_description TEXT;\\n\"`";
|
|
|
|
sqlscript="$sqlscript$part1$part2"
|
2015-05-12 21:48:42 +02:00
|
|
|
IFS="$oldIFS"
|
|
|
|
}
|
|
|
|
|
2015-07-28 12:37:33 +02:00
|
|
|
echo "Converting c_cycleinfo from VARCHAR(255) to TEXT in calendar quick tables" >&2
|
2015-05-12 21:48:42 +02:00
|
|
|
tables=`psql -t -U $username -h $hostname $database -c "select split_part(c_quick_location, '/', 5) from $indextable where c_path3 = 'Calendar';"`
|
|
|
|
|
|
|
|
for table in $tables;
|
|
|
|
do
|
2015-05-13 16:45:19 +02:00
|
|
|
adjustSchema
|
2015-05-12 21:48:42 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "$sqlscript" | psql -q -e -U $username -h $hostname $database
|