added cleanup functionality for tc_scheduling_priority during import of new data
[eq/.git] / bin / upgrade_1_0_to_2_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 # Add a new 'aaronic' column to the eq_ppi table
19 $sth = $dbh->prepare("ALTER TABLE `eq_ppi` ADD `aaronic` INT( 16 ) NOT NULL DEFAULT '0' AFTER `elder`");
20 $sth->execute or die "-E- DB error: $DBI::errstr\n";
21
22 # Parse the data out of the eq_interview table and add them to the eq_ppi table
23 $sth = $dbh->prepare("select * from eq_interview");
24 $sth->execute or die "-E- DB error: $DBI::errstr\n";
25 while($row = $sth->fetchrow_hashref) {
26         $interviewer = $row->{interviewer};
27         $elder = $row->{elder};
28         $aaronic = $row->{aaronic};
29         $date = $row->{date};
30         $notes = $row->{notes};
31         $notes =~ s/\'/\\\'/g;
32         $eqpresppi = 0;
33         #print "$interviewer $elder $aaronic $date $eqpresppi $notes\n";
34         $sth2 = $dbh->prepare("insert into eq_ppi values (NULL,'$interviewer','$elder','$aaronic','$date','$notes','$eqpresppi')");
35         $sth2->execute or die "-E- DB error: $DBI::errstr\n";
36 }
37
38 print "\n-> Succesfully imported all eq_interview table entries into eq_ppi table...\n";
39 print "-> You may drop the eq_interview table once you know all your data was transferred to the eq_ppi table correctly..\n";
40
41 ###################################################
42 # Disconnect from the database
43 $dbh->disconnect();
44 ###################################################
45
46