changed indiv fields to individual
[eq/.git] / bin / upgrade_4_0_to_5_0
index 7836351a9f890b1998f0334d55e15e4e1e1d3728..8f6d7e604cebd3f20ac265b12139734de0e74812 100755 (executable)
@@ -15,144 +15,176 @@ $dbh=DBI->connect("dbi:mysql:dbname=$dbname:host=$dbhost:port=$dbport",$dbuser,$
     PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
 ###################################################
 
-# Rename eq_aaronic table to 3rd_aaronic
-$sth = $dbh->prepare("RENAME TABLE `eq_aaronic` TO `3rd_aaronic`");
+# Remove eq_aaronic table
+$sth = $dbh->prepare("DROP TABLE IF EXISTS `eq_aaronic`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_activity table to 3rd_activity
-$sth = $dbh->prepare("RENAME TABLE `eq_activity` TO `3rd_activity`");
+# Rename eq_activity table to tc_activity
+$sth = $dbh->prepare("RENAME TABLE `eq_activity` TO `tc_activity`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_appointment table to 3rd_appointment
-$sth = $dbh->prepare("RENAME TABLE `eq_appointment` TO `3rd_appointment`");
+# Rename eq_appointment table to tc_appointment
+$sth = $dbh->prepare("RENAME TABLE `eq_appointment` TO `tc_appointment`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder field in 3rd_appointment table to indiv
-$sth = $dbh->prepare("ALTER TABLE `3rd_appointment` CHANGE `elder` `indiv` INT(16)");
+# Change elder field in tc_appointment table to indiv
+$sth = $dbh->prepare("ALTER TABLE `tc_appointment` CHANGE `elder` `indiv` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_assignment table to 3rd_assignment
-$sth = $dbh->prepare("RENAME TABLE `eq_assignment` TO `3rd_assignment`");
+# Rename eq_assignment table to tc_assignment
+$sth = $dbh->prepare("RENAME TABLE `eq_assignment` TO `tc_assignment`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_attendance table to 3rd_attendance
-$sth = $dbh->prepare("RENAME TABLE `eq_attendance` TO `3rd_attendance`");
+# Rename eq_attendance table to tc_attendance
+$sth = $dbh->prepare("RENAME TABLE `eq_attendance` TO `tc_attendance`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder field in 3rd_attendance table to indiv
-$sth = $dbh->prepare("ALTER TABLE `3rd_attendance` CHANGE `elder` `indiv` INT(16)");
+# Change elder field in tc_attendance table to indiv
+$sth = $dbh->prepare("ALTER TABLE `tc_attendance` CHANGE `elder` `indiv` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_calling table to 3rd_calling
-$sth = $dbh->prepare("RENAME TABLE `eq_calling` TO `3rd_calling`");
+# Rename eq_calling table to tc_calling
+$sth = $dbh->prepare("RENAME TABLE `eq_calling` TO `tc_calling`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_child table to 3rd_child
-$sth = $dbh->prepare("RENAME TABLE `eq_child` TO `3rd_child`");
+# Remove eq_child table
+$sth = $dbh->prepare("DROP TABLE IF EXISTS `eq_child`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_companionship table to 3rd_companionship
-$sth = $dbh->prepare("RENAME TABLE `eq_companionship` TO `3rd_companionship`");
+# Rename eq_companionship table to tc_companionship
+$sth = $dbh->prepare("RENAME TABLE `eq_companionship` TO `tc_companionship`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder field in 3rd_companionship table to indiv
-$sth = $dbh->prepare("ALTER TABLE `3rd_companionship` CHANGE `elder` `indiv` INT(16)");
+# Remove aaronic field from tc_companionship
+$sth = $dbh->prepare("ALTER TABLE `tc_companionship` DROP `aaronic`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_district table to 3rd_district
-$sth = $dbh->prepare("RENAME TABLE `eq_district` TO `3rd_district`");
+# Change elder field in tc_companionship table to indiv
+$sth = $dbh->prepare("ALTER TABLE `tc_companionship` CHANGE `elder` `indiv` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_elder table to 3rd_indiv
-$sth = $dbh->prepare("RENAME TABLE `eq_elder` TO `3rd_indiv`");
+# Rename eq_district table to tc_district
+$sth = $dbh->prepare("RENAME TABLE `eq_district` TO `tc_district`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Add a new 'propective' field to the 3rd_indiv table
-$sth = $dbh->prepare("ALTER TABLE `3rd_indiv` ADD `prospective` enum('y','n') NULL AFTER `priesthood`");
+# Rename eq_elder table to tc_indiv
+$sth = $dbh->prepare("RENAME TABLE `eq_elder` TO `tc_indiv`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder field in 3rd_indiv table to indiv
-$sth = $dbh->prepare("ALTER TABLE `3rd_indiv` CHANGE `elder` `indiv` INT(16)");
+# Change elder field in tc_indiv table to indiv
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` CHANGE `elder` `indiv` INT(16) NOT NULL AUTO_INCREMENT");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_family table to 3rd_family
-$sth = $dbh->prepare("RENAME TABLE `eq_family` TO `3rd_family`");
+# Add a new 'address' column to the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `address` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `name`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder_id field in 3rd_family table to indiv_id
-$sth = $dbh->prepare("ALTER TABLE `3rd_family` CHANGE `elder_id` `indiv_id` INT(16)");
+# Add a new 'family' column to the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `family` INT(16) UNSIGNED NULL DEFAULT NULL AFTER `email`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_parent table to 3rd_parent
-$sth = $dbh->prepare("RENAME TABLE `eq_parent` TO `3rd_parent`");
+# Add a new 'hh_position' column to the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `hh_position` ENUM( 'Head of Household', 'Spouse', 'Other' ) NOT NULL DEFAULT 'Other' AFTER `family`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_participation table to 3rd_participation
-$sth = $dbh->prepare("RENAME TABLE `eq_participation` TO `3rd_participation`");
+# Add a new 'steward' column to the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `steward` ENUM( 'High Priest', 'Elder', '' ) NULL DEFAULT NULL AFTER `priesthood`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder field in 3rd_participation table to indiv
-$sth = $dbh->prepare("ALTER TABLE `3rd_participation` CHANGE `elder` `indiv` INT(16)");
+# Rename int_pri column to hti_pri in the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` CHANGE `int_pri` `hti_pri` INT( 10 ) UNSIGNED NULL DEFAULT '1'");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_ppi table to 3rd_interview
-$sth = $dbh->prepare("RENAME TABLE `eq_ppi` TO `3rd_interview`");
+# Rename int_notes column to hti_notes in the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` CHANGE `int_notes` `hti_notes` VARCHAR( 128 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder field in 3rd_interview table to indiv
-$sth = $dbh->prepare("ALTER TABLE `3rd_interview` CHANGE `elder` `indiv` INT(16)");
+# Rename eq_family table to tc_family
+$sth = $dbh->prepare("RENAME TABLE `eq_family` TO `tc_family`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change ppi field in 3rd_interview table to interview
-$sth = $dbh->prepare("ALTER TABLE `3rd_interview` CHANGE `ppi` `interview` INT(16)");
+# Change elder_id field in tc_family table to indiv_id
+$sth = $dbh->prepare("ALTER TABLE `tc_family` CHANGE `elder_id` `indiv_id` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Add a new 'interview_type' column to the 3rd_interview table
-$sth = $dbh->prepare("ALTER TABLE `3rd_interview` ADD `interview_type` enum('hti','ppi') NOT NULL DEFAULT 'hti' AFTER `eqpresppi`");
+# Remove eq_parent table
+$sth = $dbh->prepare("DROP TABLE IF EXISTS `eq_parent`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Rename eq_participation table to tc_participation
+$sth = $dbh->prepare("RENAME TABLE `eq_participation` TO `tc_participation`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Change elder field in tc_participation table to indiv
+$sth = $dbh->prepare("ALTER TABLE `tc_participation` CHANGE `elder` `indiv` INT(16)");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Rename eq_ppi table to tc_interview
+$sth = $dbh->prepare("RENAME TABLE `eq_ppi` TO `tc_interview`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Change elder field in tc_interview table to indiv
+$sth = $dbh->prepare("ALTER TABLE `tc_interview` CHANGE `elder` `indiv` INT(16)");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Remove aaronic field from tc_interview
+$sth = $dbh->prepare("ALTER TABLE `tc_interview` DROP `aaronic`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Change ppi field in tc_interview table to interview
+$sth = $dbh->prepare("ALTER TABLE `tc_interview` CHANGE `ppi` `interview` INT(16) NOT NULL AUTO_INCREMENT");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Add a new 'interview_type' column to the tc_interview table
+$sth = $dbh->prepare("ALTER TABLE `tc_interview` ADD `interview_type` enum('hti','ppi') NOT NULL DEFAULT 'hti' AFTER `eqpresppi`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
 # set all interviews to be ppi's if eqpresppi is 1
-$sth = $dbh->prepare("UPDATE 3rd_interview SET interview_type='ppi' WHERE eqpresppi='1'");
+$sth = $dbh->prepare("UPDATE tc_interview SET interview_type='ppi' WHERE eqpresppi='1'");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# remove 'eqpresppi' from tc_interview
+$sth = $dbh->prepare("ALTER TABLE `tc_interview` DROP `eqpresppi`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# remove 'eqpresppi' from 3rd_interview
-$sth = $dbh->prepare("ALTER TABLE `3rd_interview` DROP `eqpresppi`");
+# Rename eq_presidency table to tc_presidency
+$sth = $dbh->prepare("RENAME TABLE `eq_presidency` TO `tc_presidency`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_presidency table to 3rd_presidency
-$sth = $dbh->prepare("RENAME TABLE `eq_presidency` TO `3rd_presidency`");
+# Change elder field in tc_presidency table to indiv
+$sth = $dbh->prepare("ALTER TABLE `tc_presidency` CHANGE `elder` `indiv` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder field in 3rd_presidency table to indiv
-$sth = $dbh->prepare("ALTER TABLE `3rd_presidency` CHANGE `elder` `indiv` INT(16)");
+# Remove eqpres field from tc_presidency
+$sth = $dbh->prepare("ALTER TABLE `tc_presidency` DROP `eqpres`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_visit table to 3rd_visit
-$sth = $dbh->prepare("RENAME TABLE `eq_visit` TO `3rd_visit`");
+# Rename eq_visit table to tc_visit
+$sth = $dbh->prepare("RENAME TABLE `eq_visit` TO `tc_visit`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Add a new 'companion1' column to the 3rd_visit table
-$sth = $dbh->prepare("ALTER TABLE `3rd_visit` ADD `companion1` INT( 16 ) NULL AFTER `companionship`");
+# Add a new 'companion1' column to the tc_visit table
+$sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `companion1` INT( 16 ) NULL AFTER `companionship`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Add a new 'companion2' column to the 3rd_visit table
-$sth = $dbh->prepare("ALTER TABLE `3rd_visit` ADD `companion2` INT( 16 ) NULL AFTER `companion1`");
+# Add a new 'companion2' column to the tc_visit table
+$sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `companion2` INT( 16 ) NULL AFTER `companion1`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Add a new 'visit_type' column to the 3rd_visit table
-$sth = $dbh->prepare("ALTER TABLE `3rd_visit` ADD `visit_type` enum('presidency','hometeaching') NOT NULL DEFAULT 'hometeaching' AFTER `visited`");
+# Add a new 'visit_type' column to the tc_visit table
+$sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `visit_type` enum('presidency','hometeaching') NOT NULL DEFAULT 'hometeaching' AFTER `visited`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
 # set all visits currently marked as companionship=0 with "type" "presidency" and all other visits should set to "hometeaching".
-$sth = $dbh->prepare("update 3rd_visit set visit_type='presidency' where companionship='0'");
+$sth = $dbh->prepare("update tc_visit set visit_type='presidency' where companionship='0'");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_willingness table to 3rd_willingness
-$sth = $dbh->prepare("RENAME TABLE `eq_willingness` TO `3rd_willingness`");
+# Rename eq_willingness table to tc_willingness
+$sth = $dbh->prepare("RENAME TABLE `eq_willingness` TO `tc_willingness`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Change elder field in 3rd_willingness table to indiv
-$sth = $dbh->prepare("ALTER TABLE `3rd_willingness` CHANGE `elder` `indiv` INT(16)");
+# Change elder field in tc_willingness table to indiv
+$sth = $dbh->prepare("ALTER TABLE `tc_willingness` CHANGE `elder` `indiv` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
 print "-> Done!\n";