From f16cefad3190c5d26a912638a24ca832dd94e7e1 Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Fri, 20 Jan 2012 18:43:29 +0000 Subject: [PATCH] Update the sql scripts to add a primary key to the OCSSessionFolder table. Monotone-Parent: e13dda2a639bb68b9e67d7b4dd75235d9d98ef1b Monotone-Revision: ecc0c907192778ee08a07fb020aa037de83d7bed Monotone-Author: jraby@inverse.ca Monotone-Date: 2012-01-20T18:43:29 --- Scripts/sql-update-1.3.11_to_1.3.12-mysql.sh | 36 ++++++++++++++++++++ Scripts/sql-update-1.3.11_to_1.3.12.sh | 11 ++++++ 2 files changed, 47 insertions(+) create mode 100644 Scripts/sql-update-1.3.11_to_1.3.12-mysql.sh diff --git a/Scripts/sql-update-1.3.11_to_1.3.12-mysql.sh b/Scripts/sql-update-1.3.11_to_1.3.12-mysql.sh new file mode 100644 index 000000000..50543a7f1 --- /dev/null +++ b/Scripts/sql-update-1.3.11_to_1.3.12-mysql.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# converting c_content to text is not needed on mysql as it is already big enough (mediumtext) + +# this script only works with MySQL + +defaultusername=$USER +defaulthostname=localhost +defaultdatabase=$USER + +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 + +SESSIONTBL=$(su - sogo -c "defaults read sogod OCSSessionsFolderURL" | awk -F/ '{print $NF}') +if [ -z "$SESSIONTBL" ]; then + echo "Failed to obtain session table name" >&2 + exit 1 +fi + +echo "Fix primary key for the sogo_sessions table" +mysql -p -s -u $username -h $hostname $database -e "ALTER TABLE $SESSIONTBL ADD PRIMARY KEY (c_id);" diff --git a/Scripts/sql-update-1.3.11_to_1.3.12.sh b/Scripts/sql-update-1.3.11_to_1.3.12.sh index 17b8c0405..8cf6839e8 100755 --- a/Scripts/sql-update-1.3.11_to_1.3.12.sh +++ b/Scripts/sql-update-1.3.11_to_1.3.12.sh @@ -34,6 +34,7 @@ function convVCtoText() { IFS="$oldIFS" } +echo "Step 1 - Converting c_content from VARCHAR to TEXT in table sogo_folder_info" >&2 tables=`psql -t -U $username -h $hostname $database -c "select split_part(c_location, '/', 5) from $indextable;"` for table in $tables; @@ -42,3 +43,13 @@ do done echo "$sqlscript" | psql -q -e -U $username -h $hostname $database + +echo "Step 2 - Fix primary key for the sogo_sessions table" >&2 +SESSIONTBL=$(su - sogo -c "defaults read sogod OCSSessionsFolderURL" | awk -F/ '{print $NF}') +if [ -z "$SESSIONTBL" ]; then + echo "Failed to obtain session table name" >&2 + exit 1 +fi + +psql -e -U $username -h $hostname $database -c "ALTER TABLE $SESSIONTBL ADD PRIMARY KEY (c_id);" +