Ticket #32230 Message templates not displaying in send email export
[freeside.git] / bin / freeside-upgrade-unicode
1 #!/bin/bash
2
3 # based on example code from
4 # http://blog.larik.nl:80/articles/2006/03/13/upgrade-your-postgresql-databases-to-unicode
5 # by frodo larik / blog.larik.nl
6
7 db=freeside
8
9 # This script updates all dbs to use unicode
10
11 dbhost='localhost'
12 username='freeside'
13 #odir=${HOME}/freeside_unicode_upgrade
14 odir=/home/ivan/FREESIDE_unicode_upgrade
15
16 if [ "${db}X" == "X" ]
17 then
18    echo "I need a db for host ${dbhost} and username ${username} $db" 
19    exit
20 fi
21
22 if [ ! -d $odir ]
23 then
24    mkdir $odir || exit "Exit at mkdir" 
25 fi
26
27 #echo -n "Enter a comma-separated list of country codes to keep [US,CA]:"
28 #countries=`line`
29 #if [ "${countries}X" == "X" ]
30 #then
31 #  countries='US,CA'
32 #fi
33
34 echo "delete from cust_main_county where 0 = ( select count(*) from cust_main where cust_main_county.country = cust_main.country );" | su freeside -c 'psql freeside'
35
36 dump_sql=${odir}/${db}_out.sql
37 conv_sql=${odir}/${db}_conv.sql
38 result_sql=${odir}/${db}_result.txt
39 sql_diff=${odir}/${db}.diff
40
41 # 0. stop
42
43 /etc/init.d/freeside stop || die "can't stop freeside"
44 /etc/init.d/apache stop || die "can't stop apache"
45 /etc/init.d/apache2 stop || die "can't stop apache"
46
47 echo "Dumping $db database to $dump_sql"
48
49 su $username -c "pg_dump --host=$dbhost --username=$username -D --format=p $db" >$dump_sql || exit "exit at pg_dump"
50
51 echo "Removing invalid characters from the dump"
52
53 iconv -c -f UTF-8 -t UTF-8 ${dump_sql} > ${conv_sql}  || exit "exit at iconv"
54
55 echo "*** Making a diff from the dump: check $sql_diff ***"
56
57 diff $dump_sql $conv_sql > $sql_diff
58
59 echo "Removing current database"
60
61 su $freeside -c "dropdb --host=$dbhost --username=$username $db" || exit "exit at dropdb"
62
63 echo "Creating a new databse"
64
65 su freeside -c "createdb --encoding='unicode' --host=$dbhost --username=$username $db" || exit "exit at createdb"
66
67 echo "Loading data into new database"
68 su freeside -c "psql -f $conv_sql -o $result_sql -h $dbhost -U $username $db" || exit "exit at psql ${extra_string}" 
69
70 # 99. 
71 /etc/init.d/freeside start || die "oh no, can't start freeside"
72 /etc/init.d/apache start || die "oh no, can't start apache"