Monotone-Parent: 3408f2dd09c68bd5b735490d9b4f0dd184e5f6ed

Monotone-Revision: 47bbed6cb762b2941933e8851cea9a6b681e40f4

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-08-23T20:17:46
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2007-08-23 20:17:46 +00:00
parent f3f813cf03
commit 20f22ec676
1 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,50 @@
#!/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_deleted INTEGER;\\n\"`";
sqlscript="$sqlscript$part"
IFS="$oldIFS"
}
tables=`psql -t -U $username -h $hostname $database -c "select split_part(c_location, '/', 5) from $indextable where c_folder_type != 'Container';"`
for table in $tables;
do
addField
done
sqlscript="$sqlscript;"
echo "$sqlscript" | psql -e -U $username -h $hostname $database