From 50603c67e6506643693bb539abf88297a5bbe770 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 7 Mar 2008 22:05:41 +0000 Subject: [PATCH] Monotone-Parent: 5c3fb5da8513ab5020b731e15b09dc99dab3047c Monotone-Revision: a23a8f2b57305fececc0699f4dbc0d1ae1aaac63 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-03-07T22:05:41 Monotone-Branch: ca.inverse.sogo --- Scripts/sql-update-20080303.sh | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Scripts/sql-update-20080303.sh diff --git a/Scripts/sql-update-20080303.sh b/Scripts/sql-update-20080303.sh new file mode 100644 index 000000000..e71a28b00 --- /dev/null +++ b/Scripts/sql-update-20080303.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# this script only work 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 + +echo "" +echo "You will now be requested your password twice..." +echo "After that, a list of SQL operations will scroll." +echo "" + +sqlscript="" + +function addField() { + oldIFS="$IFS" + IFS=" " + part="`echo -e \"ALTER TABLE $table ADD COLUMN c_component VARCHAR(10) NOT NULL DEFAULT 'vcard';\\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 + +echo "Please ignore the errors above. They just mean that the migration was already done for the elements in question.";