3 # this script only work with PostgreSQL
6 defaulthostname=localhost
8 indextable=sogo_folder_info
10 read -p "Username ($defaultusername): " username
11 read -p "Hostname ($defaulthostname): " hostname
12 read -p "Database ($defaultdatabase): " database
16 username=$defaultusername
20 hostname=$defaulthostname
24 database=$defaultdatabase
28 echo "You will now be requested your password twice..."
29 echo "After that, a list of SQL operations will scroll."
37 part="`echo -e \"ALTER TABLE $table ADD COLUMN c_deleted INTEGER;\\n\"`";
38 sqlscript="$sqlscript$part"
42 tables=`psql -t -U $username -h $hostname $database -c "select split_part(c_location, '/', 5) from $indextable where c_folder_type != 'Container';"`
49 sqlscript="$sqlscript;update $indextable set c_path4 = 'personal', c_path = '/Users/' || c_path2 || '/Calendar/personal' where c_path3 = 'Calendar' and c_path4 is null;"
51 function updateCalendarLocation() {
54 user="`echo $table | cut -f 1 -d :`"
55 tablename="`echo $table | cut -f 2 -d :`"
56 newstart="/$user/Calendar/personal";
57 part="update $tablename set c_object = replace(c_object, '/$user/Calendar', '$newstart') where c_object not like '$newstart%';";
58 sqlscript="$sqlscript$part"
62 tables=`psql -t -U $username -h $hostname $database -c "select c_path2 || ':' || split_part(c_acl_location, '/', 5) from $indextable where c_folder_type = 'Appointment';"`
65 updateCalendarLocation
68 echo "$sqlscript" | psql -q -e -U $username -h $hostname $database > /dev/null
70 echo "Please ignore the errors above. They just mean that the migration was already done for the elements in question.";