c_content TEXT to LONGTEXT for OpenChange tables

Add an script to update existing tables.
Note that if a row already have 65535 char in it,
the data is most likely broken.
pull/10/head
Jean Raby 2013-03-05 10:47:09 -05:00
parent 7e8a83aefb
commit 13277bbdb9
2 changed files with 53 additions and 1 deletions

View File

@ -79,7 +79,7 @@
@" c_lastmodified INT NOT NULL,"
@" c_version INT NOT NULL DEFAULT 0,"
@" c_deleted TINYINT NOT NULL DEFAULT 0,"
@" c_content TEXT)");
@" c_content LONGTEXT)");
return [NSString stringWithFormat: sqlFolderFormat, tableName];
}

View File

@ -0,0 +1,52 @@
#!/bin/bash
set -e
# This script only works with mysql
# updates c_content to longtext in SOGo/OpenChange cache tables
# to avoid truncation of data at 64k
defaultusername=$USER
defaulthostname=127.0.0.1
defaultdatabase=sogo
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=""
function growContent() {
oldIFS="$IFS"
IFS=" "
part="`echo -e \"ALTER TABLE $table MODIFY c_content LONGTEXT;\\n\"`";
sqlscript="$sqlscript$part"
IFS="$oldIFS"
}
echo "This script will ask for the sql password twice" >&2
echo "Converting c_content from TEXT to LONGTEXT in SOGo/OpenChange cache tables" >&2
tables=`mysql -p -s -u $username -h $hostname $database -e "show tables like 'socfs_%';"`
for table in $tables;
do
growContent
done
echo "$sqlscript" | mysql -p -s -u $username -h $hostname $database