From 10d31609e9f447202816d2721333e0d83f5c4f0a Mon Sep 17 00:00:00 2001
From: Owen Leonard <owen@balawis.leonard.fam>
Date: Fri, 29 Oct 2010 22:05:23 -0600
Subject: [PATCH] changed visit_type to type

---
 bin/import_ward_data       |  2 +-
 bin/upgrade_1_1_0_to_1_1_1 | 10 ++++++++++
 sql/schema.dot             |  2 +-
 sql/tc.sql                 |  2 +-
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/bin/import_ward_data b/bin/import_ward_data
index 57d450f..3f08fc0 100755
--- a/bin/import_ward_data
+++ b/bin/import_ward_data
@@ -615,7 +615,7 @@ sub update_tc_visit_table
 				if ($importing_status ne '')
 				{
 					# add visit if it doesn't exist in tc_visit
-					$sth = $dbh->prepare("insert into tc_visit values (NULL, '$family_id', '$comp_id', '', '', '$visit_date', '', '$importing_status', 'hometeaching')");
+					$sth = $dbh->prepare("insert into tc_visit values (NULL, '$family_id', '$comp_id', '', '', '$visit_date', '', '$importing_status', 'H')");
 					$sth->execute or die "-E- DB error: $DBI::errstr\n";
 				}
 			}
diff --git a/bin/upgrade_1_1_0_to_1_1_1 b/bin/upgrade_1_1_0_to_1_1_1
index 904133d..9bb7ff6 100755
--- a/bin/upgrade_1_1_0_to_1_1_1
+++ b/bin/upgrade_1_1_0_to_1_1_1
@@ -26,6 +26,16 @@ $sth->execute or die "-E- DB error: $DBI::errstr\n";
 $sth = $dbh->prepare("ALTER TABLE `tc_interview` DROP `interview_type` ");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
+# Change visit_type field in tc_visit table to type, change enum to use 'H','P'
+$sth = $dbh->prepare("ALTER TABLE `tc_visit` ADD `type` ENUM( 'H', 'P' ) NOT NULL AFTER `visit_type`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+$sth = $dbh->prepare("UPDATE tc_visit SET type='H' WHERE visit_type='hometeaching'");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+$sth = $dbh->prepare("UPDATE tc_visit SET type='P' WHERE visit_type='presidency'");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+$sth = $dbh->prepare("ALTER TABLE `tc_visit` DROP `visit_type` ");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
 print "-> Done!\n";
 
 ###################################################
diff --git a/sql/schema.dot b/sql/schema.dot
index ec23ab7..9f5e512 100644
--- a/sql/schema.dot
+++ b/sql/schema.dot
@@ -55,7 +55,7 @@ digraph schema {
     shape = "record"
   ];
   visit   [
-    label = "visit||<v> visit|<f> family|<c> companionship|<c1> companion1|<c2> companion2|<t> date|<n> notes|<v> visited|<vt> visit_type"
+    label = "visit||<v> visit|<f> family|<c> companionship|<c1> companion1|<c2> companion2|<t> date|<n> notes|<v> visited|<vt> type"
     shape = "record"
   ];
   willingness   [
diff --git a/sql/tc.sql b/sql/tc.sql
index d66b728..f5520db 100644
--- a/sql/tc.sql
+++ b/sql/tc.sql
@@ -182,7 +182,7 @@ CREATE TABLE /*!42501 IF NOT EXISTS*/ `tc_visit` (
   `date` date default NULL,
   `notes` text,
   `visited` enum('y','n','') default NULL,
-  `visit_type` enum('presidency','hometeaching') not null default 'hometeaching',
+  `type` enum('P','H') not null default 'H',
   PRIMARY KEY  (`visit`)
 ) ENGINE=MyISAM AUTO_INCREMENT=9513 DEFAULT CHARSET=latin1;
 
-- 
2.34.1