5b63644e6a
Monotone-Revision: 5a4a7c1db4a25a06a5e157e4f3556f764c632fa8 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-05-18T18:35:47 Monotone-Branch: ca.inverse.sogo
45 lines
958 B
Bash
Executable file
45 lines
958 B
Bash
Executable file
#!/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 addField() {
|
|
oldIFS="$IFS"
|
|
IFS=" "
|
|
part="`echo -e \"ALTER TABLE $table ADD COLUMN c_category VARCHAR(255);\\n\"`";
|
|
sqlscript="$sqlscript$part"
|
|
IFS="$oldIFS"
|
|
}
|
|
|
|
tables=`psql -t -U $username -h $hostname $database -c "select split_part(c_quick_location, '/', 5) from $indextable where c_folder_type = 'Appointment';"`
|
|
|
|
for table in $tables;
|
|
do
|
|
addField
|
|
done
|
|
|
|
echo "$sqlscript" | psql -q -e -U $username -h $hostname $database > /dev/null
|