remove eqpres from tc_presidency table - just used the president field instead -...
[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 # Remove eq_aaronic table
19 $sth = $dbh->prepare("DROP TABLE IF EXISTS `eq_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 # Remove eq_child table
51 $sth = $dbh->prepare("DROP TABLE IF EXISTS `eq_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 # Remove aaronic field from tc_companionship
59 $sth = $dbh->prepare("ALTER TABLE `tc_companionship` DROP `aaronic`");
60 $sth->execute or die "-E- DB error: $DBI::errstr\n";
61
62 # Change elder field in tc_companionship table to indiv
63 $sth = $dbh->prepare("ALTER TABLE `tc_companionship` CHANGE `elder` `indiv` INT(16)");
64 $sth->execute or die "-E- DB error: $DBI::errstr\n";
65
66 # Rename eq_district table to tc_district
67 $sth = $dbh->prepare("RENAME TABLE `eq_district` TO `tc_district`");
68 $sth->execute or die "-E- DB error: $DBI::errstr\n";
69
70 # Rename eq_elder table to tc_indiv
71 $sth = $dbh->prepare("RENAME TABLE `eq_elder` TO `tc_indiv`");
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) NOT NULL AUTO_INCREMENT");
76 $sth->execute or die "-E- DB error: $DBI::errstr\n";
77
78 # Add a new 'address' column to the tc_indiv table
79 $sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `address` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `name`");
80 $sth->execute or die "-E- DB error: $DBI::errstr\n";
81
82 # Add a new 'family' column to the tc_indiv table
83 $sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `family` INT(16) UNSIGNED NULL DEFAULT NULL AFTER `email`");
84 $sth->execute or die "-E- DB error: $DBI::errstr\n";
85
86 # Add a new 'hh_position' column to the tc_indiv table
87 $sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `hh_position` ENUM( 'Head of Household', 'Spouse', 'Other' ) NOT NULL DEFAULT 'Other' AFTER `family`");
88 $sth->execute or die "-E- DB error: $DBI::errstr\n";
89
90 # Add a new 'steward' column to the tc_indiv table
91 $sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `steward` ENUM( 'High Priest', 'Elder', '' ) NULL DEFAULT NULL AFTER `priesthood`");
92 $sth->execute or die "-E- DB error: $DBI::errstr\n";
93
94 # Rename eq_family table to tc_family
95 $sth = $dbh->prepare("RENAME TABLE `eq_family` TO `tc_family`");
96 $sth->execute or die "-E- DB error: $DBI::errstr\n";
97
98 # Change elder_id field in tc_family table to indiv_id
99 $sth = $dbh->prepare("ALTER TABLE `tc_family` CHANGE `elder_id` `indiv_id` INT(16)");
100 $sth->execute or die "-E- DB error: $DBI::errstr\n";
101
102 # Remove eq_parent table
103 $sth = $dbh->prepare("DROP TABLE IF EXISTS `eq_parent`");
104 $sth->execute or die "-E- DB error: $DBI::errstr\n";
105
106 # Rename eq_participation table to tc_participation
107 $sth = $dbh->prepare("RENAME TABLE `eq_participation` TO `tc_participation`");
108 $sth->execute or die "-E- DB error: $DBI::errstr\n";
109
110 # Change elder field in tc_participation table to indiv
111 $sth = $dbh->prepare("ALTER TABLE `tc_participation` CHANGE `elder` `indiv` INT(16)");
112 $sth->execute or die "-E- DB error: $DBI::errstr\n";
113
114 # Rename eq_ppi table to tc_interview
115 $sth = $dbh->prepare("RENAME TABLE `eq_ppi` TO `tc_interview`");
116 $sth->execute or die "-E- DB error: $DBI::errstr\n";
117
118 # Change elder field in tc_interview table to indiv
119 $sth = $dbh->prepare("ALTER TABLE `tc_interview` CHANGE `elder` `indiv` INT(16)");
120 $sth->execute or die "-E- DB error: $DBI::errstr\n";
121
122 # Remove aaronic field from tc_interview
123 $sth = $dbh->prepare("ALTER TABLE `tc_interview` DROP `aaronic`");
124 $sth->execute or die "-E- DB error: $DBI::errstr\n";
125
126 # Change ppi field in tc_interview table to interview
127 $sth = $dbh->prepare("ALTER TABLE `tc_interview` CHANGE `ppi` `interview` INT(16) NOT NULL AUTO_INCREMENT");
128 $sth->execute or die "-E- DB error: $DBI::errstr\n";
129
130 # Add a new 'interview_type' column to the tc_interview table
131 $sth = $dbh->prepare("ALTER TABLE `tc_interview` ADD `interview_type` enum('hti','ppi') NOT NULL DEFAULT 'hti' AFTER `eqpresppi`");
132 $sth->execute or die "-E- DB error: $DBI::errstr\n";
133
134 # set all interviews to be ppi's if eqpresppi is 1
135 $sth = $dbh->prepare("UPDATE tc_interview SET interview_type='ppi' WHERE eqpresppi='1'");
136 $sth->execute or die "-E- DB error: $DBI::errstr\n";
137
138 # remove 'eqpresppi' from tc_interview
139 $sth = $dbh->prepare("ALTER TABLE `tc_interview` DROP `eqpresppi`");
140 $sth->execute or die "-E- DB error: $DBI::errstr\n";
141
142 # Rename eq_presidency table to tc_presidency
143 $sth = $dbh->prepare("RENAME TABLE `eq_presidency` TO `tc_presidency`");
144 $sth->execute or die "-E- DB error: $DBI::errstr\n";
145
146 # Change elder field in tc_presidency table to indiv
147 $sth = $dbh->prepare("ALTER TABLE `tc_presidency` CHANGE `elder` `indiv` INT(16)");
148 $sth->execute or die "-E- DB error: $DBI::errstr\n";
149
150 # Remove eqpres field from tc_presidency
151 $sth = $dbh->prepare("ALTER TABLE `tc_presidency` DROP `eqpres`");
152 $sth->execute or die "-E- DB error: $DBI::errstr\n";
153
154 # Rename eq_visit table to tc_visit
155 $sth = $dbh->prepare("RENAME TABLE `eq_visit` TO `tc_visit`");
156 $sth->execute or die "-E- DB error: $DBI::errstr\n";
157
158 # Add a new 'companion1' column to the tc_visit table
159 $sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `companion1` INT( 16 ) NULL AFTER `companionship`");
160 $sth->execute or die "-E- DB error: $DBI::errstr\n";
161
162 # Add a new 'companion2' column to the tc_visit table
163 $sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `companion2` INT( 16 ) NULL AFTER `companion1`");
164 $sth->execute or die "-E- DB error: $DBI::errstr\n";
165
166 # Add a new 'visit_type' column to the tc_visit table
167 $sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `visit_type` enum('presidency','hometeaching') NOT NULL DEFAULT 'hometeaching' AFTER `visited`");
168 $sth->execute or die "-E- DB error: $DBI::errstr\n";
169
170 # set all visits currently marked as companionship=0 with "type" "presidency" and all other visits should set to "hometeaching".
171 $sth = $dbh->prepare("update tc_visit set visit_type='presidency' where companionship='0'");
172 $sth->execute or die "-E- DB error: $DBI::errstr\n";
173
174 # Rename eq_willingness table to tc_willingness
175 $sth = $dbh->prepare("RENAME TABLE `eq_willingness` TO `tc_willingness`");
176 $sth->execute or die "-E- DB error: $DBI::errstr\n";
177
178 # Change elder field in tc_willingness table to indiv
179 $sth = $dbh->prepare("ALTER TABLE `tc_willingness` CHANGE `elder` `indiv` INT(16)");
180 $sth->execute or die "-E- DB error: $DBI::errstr\n";
181
182 print "-> Done!\n";
183
184 ###################################################
185 # Disconnect from the database
186 $dbh->disconnect();
187 ###################################################
188
189