changed app name to tc
[eq/.git] / bin / upgrade_4_0_to_5_0
1 #!/usr/bin/perl
2
3 use DBI;
4 use Getopt::Std;
5
6 $mydir = `cd \$(dirname $0) 2>/dev/null; pwd`; chomp($mydir);
7 unshift @INC,("$mydir/../setup");
8 if( -f "$mydir/../setup/db_config.local") { require "db_config.local"; }
9 else { require "db_config"; }
10
11 ###################################################
12 # Connect to the database
13 $dbh=DBI->connect("dbi:mysql:dbname=$dbname:host=$dbhost:port=$dbport",$dbuser,$dbpass,{
14     AutoCommit=>0,
15     PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
16 ###################################################
17
18 # Rename eq_aaronic table to tc_aaronic
19 $sth = $dbh->prepare("RENAME TABLE `eq_aaronic` TO `tc_aaronic`");
20 $sth->execute or die "-E- DB error: $DBI::errstr\n";
21
22 # Rename eq_activity table to tc_activity
23 $sth = $dbh->prepare("RENAME TABLE `eq_activity` TO `tc_activity`");
24 $sth->execute or die "-E- DB error: $DBI::errstr\n";
25
26 # Rename eq_appointment table to tc_appointment
27 $sth = $dbh->prepare("RENAME TABLE `eq_appointment` TO `tc_appointment`");
28 $sth->execute or die "-E- DB error: $DBI::errstr\n";
29
30 # Change elder field in tc_appointment table to indiv
31 $sth = $dbh->prepare("ALTER TABLE `tc_appointment` CHANGE `elder` `indiv` INT(16)");
32 $sth->execute or die "-E- DB error: $DBI::errstr\n";
33
34 # Rename eq_assignment table to tc_assignment
35 $sth = $dbh->prepare("RENAME TABLE `eq_assignment` TO `tc_assignment`");
36 $sth->execute or die "-E- DB error: $DBI::errstr\n";
37
38 # Rename eq_attendance table to tc_attendance
39 $sth = $dbh->prepare("RENAME TABLE `eq_attendance` TO `tc_attendance`");
40 $sth->execute or die "-E- DB error: $DBI::errstr\n";
41
42 # Change elder field in tc_attendance table to indiv
43 $sth = $dbh->prepare("ALTER TABLE `tc_attendance` CHANGE `elder` `indiv` INT(16)");
44 $sth->execute or die "-E- DB error: $DBI::errstr\n";
45
46 # Rename eq_calling table to tc_calling
47 $sth = $dbh->prepare("RENAME TABLE `eq_calling` TO `tc_calling`");
48 $sth->execute or die "-E- DB error: $DBI::errstr\n";
49
50 # Rename eq_child table to tc_child
51 $sth = $dbh->prepare("RENAME TABLE `eq_child` TO `tc_child`");
52 $sth->execute or die "-E- DB error: $DBI::errstr\n";
53
54 # Rename eq_companionship table to tc_companionship
55 $sth = $dbh->prepare("RENAME TABLE `eq_companionship` TO `tc_companionship`");
56 $sth->execute or die "-E- DB error: $DBI::errstr\n";
57
58 # Change elder field in tc_companionship table to indiv
59 $sth = $dbh->prepare("ALTER TABLE `tc_companionship` CHANGE `elder` `indiv` INT(16)");
60 $sth->execute or die "-E- DB error: $DBI::errstr\n";
61
62 # Rename eq_district table to tc_district
63 $sth = $dbh->prepare("RENAME TABLE `eq_district` TO `tc_district`");
64 $sth->execute or die "-E- DB error: $DBI::errstr\n";
65
66 # Rename eq_elder table to tc_indiv
67 $sth = $dbh->prepare("RENAME TABLE `eq_elder` TO `tc_indiv`");
68 $sth->execute or die "-E- DB error: $DBI::errstr\n";
69
70 # Add a new 'propective' field to the tc_indiv table
71 $sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `prospective` enum('y','n') NULL AFTER `priesthood`");
72 $sth->execute or die "-E- DB error: $DBI::errstr\n";
73
74 # Change elder field in tc_indiv table to indiv
75 $sth = $dbh->prepare("ALTER TABLE `tc_indiv` CHANGE `elder` `indiv` INT(16)");
76 $sth->execute or die "-E- DB error: $DBI::errstr\n";
77
78 # Rename eq_family table to tc_family
79 $sth = $dbh->prepare("RENAME TABLE `eq_family` TO `tc_family`");
80 $sth->execute or die "-E- DB error: $DBI::errstr\n";
81
82 # Change elder_id field in tc_family table to indiv_id
83 $sth = $dbh->prepare("ALTER TABLE `tc_family` CHANGE `elder_id` `indiv_id` INT(16)");
84 $sth->execute or die "-E- DB error: $DBI::errstr\n";
85
86 # Rename eq_parent table to tc_parent
87 $sth = $dbh->prepare("RENAME TABLE `eq_parent` TO `tc_parent`");
88 $sth->execute or die "-E- DB error: $DBI::errstr\n";
89
90 # Rename eq_participation table to tc_participation
91 $sth = $dbh->prepare("RENAME TABLE `eq_participation` TO `tc_participation`");
92 $sth->execute or die "-E- DB error: $DBI::errstr\n";
93
94 # Change elder field in tc_participation table to indiv
95 $sth = $dbh->prepare("ALTER TABLE `tc_participation` CHANGE `elder` `indiv` INT(16)");
96 $sth->execute or die "-E- DB error: $DBI::errstr\n";
97
98 # Rename eq_ppi table to tc_interview
99 $sth = $dbh->prepare("RENAME TABLE `eq_ppi` TO `tc_interview`");
100 $sth->execute or die "-E- DB error: $DBI::errstr\n";
101
102 # Change elder field in tc_interview table to indiv
103 $sth = $dbh->prepare("ALTER TABLE `tc_interview` CHANGE `elder` `indiv` INT(16)");
104 $sth->execute or die "-E- DB error: $DBI::errstr\n";
105
106 # Change ppi field in tc_interview table to interview
107 $sth = $dbh->prepare("ALTER TABLE `tc_interview` CHANGE `ppi` `interview` INT(16)");
108 $sth->execute or die "-E- DB error: $DBI::errstr\n";
109
110 # Add a new 'interview_type' column to the tc_interview table
111 $sth = $dbh->prepare("ALTER TABLE `tc_interview` ADD `interview_type` enum('hti','ppi') NOT NULL DEFAULT 'hti' AFTER `eqpresppi`");
112 $sth->execute or die "-E- DB error: $DBI::errstr\n";
113
114 # set all interviews to be ppi's if eqpresppi is 1
115 $sth = $dbh->prepare("UPDATE tc_interview SET interview_type='ppi' WHERE eqpresppi='1'");
116 $sth->execute or die "-E- DB error: $DBI::errstr\n";
117
118 # remove 'eqpresppi' from tc_interview
119 $sth = $dbh->prepare("ALTER TABLE `tc_interview` DROP `eqpresppi`");
120 $sth->execute or die "-E- DB error: $DBI::errstr\n";
121
122 # Rename eq_presidency table to tc_presidency
123 $sth = $dbh->prepare("RENAME TABLE `eq_presidency` TO `tc_presidency`");
124 $sth->execute or die "-E- DB error: $DBI::errstr\n";
125
126 # Change elder field in tc_presidency table to indiv
127 $sth = $dbh->prepare("ALTER TABLE `tc_presidency` CHANGE `elder` `indiv` INT(16)");
128 $sth->execute or die "-E- DB error: $DBI::errstr\n";
129
130 # Rename eq_visit table to tc_visit
131 $sth = $dbh->prepare("RENAME TABLE `eq_visit` TO `tc_visit`");
132 $sth->execute or die "-E- DB error: $DBI::errstr\n";
133
134 # Add a new 'companion1' column to the tc_visit table
135 $sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `companion1` INT( 16 ) NULL AFTER `companionship`");
136 $sth->execute or die "-E- DB error: $DBI::errstr\n";
137
138 # Add a new 'companion2' column to the tc_visit table
139 $sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `companion2` INT( 16 ) NULL AFTER `companion1`");
140 $sth->execute or die "-E- DB error: $DBI::errstr\n";
141
142 # Add a new 'visit_type' column to the tc_visit table
143 $sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `visit_type` enum('presidency','hometeaching') NOT NULL DEFAULT 'hometeaching' AFTER `visited`");
144 $sth->execute or die "-E- DB error: $DBI::errstr\n";
145
146 # set all visits currently marked as companionship=0 with "type" "presidency" and all other visits should set to "hometeaching".
147 $sth = $dbh->prepare("update tc_visit set visit_type='presidency' where companionship='0'");
148 $sth->execute or die "-E- DB error: $DBI::errstr\n";
149
150 # Rename eq_willingness table to tc_willingness
151 $sth = $dbh->prepare("RENAME TABLE `eq_willingness` TO `tc_willingness`");
152 $sth->execute or die "-E- DB error: $DBI::errstr\n";
153
154 # Change elder field in tc_willingness table to indiv
155 $sth = $dbh->prepare("ALTER TABLE `tc_willingness` CHANGE `elder` `indiv` INT(16)");
156 $sth->execute or die "-E- DB error: $DBI::errstr\n";
157
158 print "-> Done!\n";
159
160 ###################################################
161 # Disconnect from the database
162 $dbh->disconnect();
163 ###################################################
164
165