Monotone-Parent: a02bbe9f2e1f3a2c472f0499b21e163f8b6170ec

Monotone-Revision: fc67c49fbd49fb6ce4ebc0af25642bc75b7652ad

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-10-26T20:15:01
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2010-10-26 20:15:01 +00:00
parent 12df5036f6
commit f787ec513f
7 changed files with 112 additions and 2 deletions
@@ -0,0 +1,45 @@
#!/bin/bash
# this script only works with MySQL
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_categories VARCHAR(255);\\n\"`";
sqlscript="$sqlscript$part"
IFS="$oldIFS"
}
tables=`mysql -p -N -B -u $username -h $hostname $database -e "select SUBSTRING_INDEX(c_quick_location, '/', -1) from $indextable where c_folder_type = 'Contact';"`
for table in $tables;
do
addField
done
echo "$sqlscript" | mysql -p -s -u $username -h $hostname $database > /dev/null
+44
View File
@@ -0,0 +1,44 @@
#!/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_categories 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 = 'Contact';"`
for table in $tables;
do
addField
done
echo "$sqlscript" | psql -q -e -U $username -h $hostname $database > /dev/null