File: sql-update-1.3.11_to_1.3.12.sh

package info (click to toggle)
sogo 1.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 21,620 kB
  • sloc: objc: 99,218; python: 4,840; sh: 1,217; perl: 861; makefile: 132; sql: 53; php: 43; ansic: 4
file content (55 lines) | stat: -rwxr-xr-x 1,347 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash

# This script only works with PostgreSQL

defaultusername=$USER
defaulthostname=localhost
defaultdatabase=$USER
indextable=sogo_folder_info

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 convVCtoText() {
    oldIFS="$IFS"
    IFS=" "
    part="`echo -e \"ALTER TABLE $table ALTER COLUMN c_content TYPE TEXT;\\n\"`";
    sqlscript="$sqlscript$part"
    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;
do
  convVCtoText
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);"