3098d49ce374592b97afef109bbd2aede64099c3
[eq/.git] / bin / upgrade_1_1_0_to_1_1_1
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
9 if( -f "$mydir/../setup/db_config.local") { require "db_config.local"; }
10 else { require "db_config"; }
11
12 ###################################################
13 # Connect to the database
14 $dbh=DBI->connect("dbi:mysql:dbname=$dbname:host=$dbhost:port=$dbport",$dbuser,$dbpass,{
15     AutoCommit=>0,
16     PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
17 ###################################################
18
19 # Change interview_type field in tc_interview table to type, change enum to use 'H','P'
20 $sth = $dbh->prepare("ALTER TABLE `tc_interview` ADD `type` ENUM( 'H', 'P' ) NOT NULL AFTER `interview_type`");
21 $sth->execute or die "-E- DB error: $DBI::errstr\n";
22 $sth = $dbh->prepare("UPDATE tc_interview SET type='H' WHERE interview_type='hti'");
23 $sth->execute or die "-E- DB error: $DBI::errstr\n";
24 $sth = $dbh->prepare("UPDATE tc_interview SET type='P' WHERE interview_type='ppi'");
25 $sth->execute or die "-E- DB error: $DBI::errstr\n";
26 $sth = $dbh->prepare("ALTER TABLE `tc_interview` DROP `interview_type` ");
27 $sth->execute or die "-E- DB error: $DBI::errstr\n";
28
29 # Change visit_type field in tc_visit table to type, change enum to use 'H','P'
30 $sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `type` ENUM( 'H', 'P' ) NOT NULL AFTER `visit_type`");
31 $sth->execute or die "-E- DB error: $DBI::errstr\n";
32 $sth = $dbh->prepare("UPDATE tc_visit SET type='H' WHERE visit_type='hometeaching'");
33 $sth->execute or die "-E- DB error: $DBI::errstr\n";
34 $sth = $dbh->prepare("UPDATE tc_visit SET type='P' WHERE visit_type='presidency'");
35 $sth->execute or die "-E- DB error: $DBI::errstr\n";
36 $sth = $dbh->prepare("ALTER TABLE `tc_visit` DROP `visit_type` ");
37 $sth->execute or die "-E- DB error: $DBI::errstr\n";
38
39 # add type field to tc_companionship
40 $sth = $dbh->prepare("ALTER TABLE `tc_companionship` ADD `type` ENUM( 'H', 'P' ) NOT NULL DEFAULT 'H' AFTER `district`");
41 $sth->execute or die "-E- DB error: $DBI::errstr\n";
42
43 # rename supervisor field in tc_district to leader
44 $sth = $dbh->prepare("ALTER TABLE `tc_district` CHANGE `supervisor` `leader` INT( 16 ) UNSIGNED NULL DEFAULT NULL");
45 $sth->execute or die "-E- DB error: $DBI::errstr\n";
46
47 # rename supervisor field in tc_district_sandbox to leader
48 $sth = $dbh->prepare("ALTER TABLE `tc_district_sandbox` CHANGE `supervisor` `leader` INT( 16 ) UNSIGNED NULL DEFAULT NULL");
49 $sth->execute or die "-E- DB error: $DBI::errstr\n";
50
51 # rename presidency field in tc_appointment to leader
52 $sth = $dbh->prepare("ALTER TABLE `tc_appointment` CHANGE `presidency` `leader` INT( 16 ) UNSIGNED NOT NULL DEFAULT '0'");
53 $sth->execute or die "-E- DB error: $DBI::errstr\n";
54
55 # rename presidency field in tc_leader to leader
56 $sth = $dbh->prepare("ALTER TABLE `tc_presidency` CHANGE `presidency` `leader` INT( 16 ) UNSIGNED NOT NULL AUTO_INCREMENT");
57 $sth->execute or die "-E- DB error: $DBI::errstr\n";
58
59 # rename tc_presidency to tc_leader
60 $sth = $dbh->prepare("RENAME TABLE `tc_presidency` TO `tc_leader`");
61 $sth->execute or die "-E- DB error: $DBI::errstr\n";
62
63 print "-> Done!\n";
64
65 ###################################################
66 # Disconnect from the database
67 $dbh->disconnect();
68 ###################################################