← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19995: use InitTableAlteror to upgrade de.valueTypes

 

------------------------------------------------------------
revno: 19995
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-09-04 18:23:32 +0700
message:
  use InitTableAlteror to upgrade de.valueTypes
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java	2015-07-02 07:05:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java	2015-09-04 11:23:32 +0000
@@ -46,7 +46,7 @@
 
     @Autowired
     private StatementManager statementManager;
-    
+
     @Autowired
     private StatementBuilder statementBuilder;
 
@@ -69,39 +69,77 @@
         executeSql( "UPDATE programstageinstance SET status='COMPLETED' WHERE status='1';" );
         executeSql( "UPDATE programstageinstance SET status='SKIPPED' WHERE status='5';" );
         executeSql( "ALTER TABLE program DROP COLUMN displayonallorgunit" );
-        
+
         upgradeProgramStageDataElements();
-        
-        executeSql( "ALTER TABLE program ALTER COLUMN \"type\" TYPE varchar(255);");
-        executeSql( "update program set \"type\"='WITH_REGISTRATION' where type='1' or type='2'");
-        executeSql( "update program set \"type\"='WITHOUT_REGISTRATION' where type='3'");
+        updateValueTypes();
+
+        executeSql( "ALTER TABLE program ALTER COLUMN \"type\" TYPE varchar(255);" );
+        executeSql( "update program set \"type\"='WITH_REGISTRATION' where type='1' or type='2'" );
+        executeSql( "update program set \"type\"='WITHOUT_REGISTRATION' where type='3'" );
     }
 
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
 
+    private void updateValueTypes()
+    {
+        executeSql( "alter table dataelement alter column valuetype type varchar(50)" );
+
+        executeSql( "update dataelement set valuetype='NUMBER' where valuetype='int' and numbertype='number'" );
+        executeSql( "update dataelement set valuetype='INTEGER' where valuetype='int' and numbertype='int'" );
+        executeSql( "update dataelement set valuetype='INTEGER_POSITIVE' where valuetype='int' and numbertype='posInt'" );
+        executeSql( "update dataelement set valuetype='INTEGER_NEGATIVE' where valuetype='int' and numbertype='negInt'" );
+        executeSql( "update dataelement set valuetype='INTEGER_ZERO_OR_POSITIVE' where valuetype='int' and numbertype='zeroPositiveInt'" );
+        executeSql( "update dataelement set valuetype='PERCENTAGE' where valuetype='int' and numbertype='percentage'" );
+        executeSql( "update dataelement set valuetype='UNIT_INTERVAL' where valuetype='int' and numbertype='unitInterval'" );
+
+        executeSql( "update dataelement set valuetype='TEXT' where valuetype='string' and texttype='text'" );
+        executeSql( "update dataelement set valuetype='LONG_TEXT' where valuetype='string' and texttype='longText'" );
+
+        executeSql( "update dataelement set valuetype='DATE' where valuetype='date'" );
+        executeSql( "update dataelement set valuetype='DATETIME' where valuetype='datetime'" );
+        executeSql( "update dataelement set valuetype='BOOLEAN' where valuetype='bool'" );
+        executeSql( "update dataelement set valuetype='TRUE_ONLY' where valuetype='trueOnly'" );
+        executeSql( "update dataelement set valuetype='USERNAME' where valuetype='username'" );
+
+        executeSql( "alter table dataelement drop column numbertype" );
+        executeSql( "alter table dataelement drop column texttype" );
+
+        executeSql( "update trackedentityattribute set valuetype='TEXT' where valuetype='string'" );
+        executeSql( "update trackedentityattribute set valuetype='PHONE_NUMBER' where valuetype='phoneNumber'" );
+        executeSql( "update trackedentityattribute set valuetype='EMAIL' where valuetype='email'" );
+        executeSql( "update trackedentityattribute set valuetype='NUMBER' where valuetype='number'" );
+        executeSql( "update trackedentityattribute set valuetype='LETTER' where valuetype='letter'" );
+        executeSql( "update trackedentityattribute set valuetype='BOOLEAN' where valuetype='bool'" );
+        executeSql( "update trackedentityattribute set valuetype='TRUE_ONLY' where valuetype='trueOnly'" );
+        executeSql( "update trackedentityattribute set valuetype='DATE' where valuetype='date'" );
+        executeSql( "update trackedentityattribute set valuetype='OPTION_SET' where valuetype='optionSet'" );
+        executeSql( "update trackedentityattribute set valuetype='TRACKER_ASSOCIATE' where valuetype='trackerAssociate'" );
+        executeSql( "update trackedentityattribute set valuetype='USERNAME' where valuetype='users'" );
+    }
+
     private void upgradeProgramStageDataElements()
     {
         if ( tableExists( "programstage_dataelements" ) )
         {
             String autoIncr = statementBuilder.getAutoIncrementValue();
-            
-            String insertSql = 
+
+            String insertSql =
                 "insert into programstagedataelement(programstagedataelementid,programstageid,dataelementid,compulsory,allowprovidedelsewhere,sort_order,displayinreports,programstagesectionid,allowfuturedate,section_sort_order) " +
-                "select " + autoIncr + ",programstageid,dataelementid,compulsory,allowprovidedelsewhere,sort_order,displayinreports,programstagesectionid,allowfuturedate,section_sort_order " +
-                "from programstage_dataelements";
-            
+                    "select " + autoIncr + ",programstageid,dataelementid,compulsory,allowprovidedelsewhere,sort_order,displayinreports,programstagesectionid,allowfuturedate,section_sort_order " +
+                    "from programstage_dataelements";
+
             executeSql( insertSql );
-            
+
             String dropSql = "drop table programstage_dataelements";
-            
+
             executeSql( dropSql );
-            
+
             log.info( "Upgraded program stage data elements" );
         }
     }
-    
+
     private int executeSql( String sql )
     {
         try
@@ -115,7 +153,7 @@
             return -1;
         }
     }
-    
+
     private boolean tableExists( String table )
     {
         try

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2015-09-04 10:49:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2015-09-04 11:23:32 +0000
@@ -870,50 +870,11 @@
         upgradeAggregationType( "chart" );
 
         updateRelativePeriods();
-        updateValueTypes();
         organisationUnitService.updatePaths();
 
         log.info( "Tables updated" );
     }
 
-    private void updateValueTypes()
-    {
-        executeSql( "alter table dataelement alter column valuetype type varchar(50)" );
-
-        executeSql( "update dataelement set vtype='NUMBER' where valuetype='int' and numbertype='number'" );
-        executeSql( "update dataelement set vtype='INTEGER' where valuetype='int' and numbertype='int'" );
-        executeSql( "update dataelement set vtype='INTEGER_POSITIVE' where valuetype='int' and numbertype='posInt'" );
-        executeSql( "update dataelement set vtype='INTEGER_NEGATIVE' where valuetype='int' and numbertype='negInt'" );
-        executeSql( "update dataelement set vtype='INTEGER_ZERO_OR_POSITIVE' where valuetype='int' and numbertype='zeroPositiveInt'" );
-        executeSql( "update dataelement set vtype='PERCENTAGE' where valuetype='int' and numbertype='percentage'" );
-        executeSql( "update dataelement set vtype='UNIT_INTERVAL' where valuetype='int' and numbertype='unitInterval'" );
-
-        executeSql( "update dataelement set vtype='TEXT' where valuetype='string' and texttype='text'" );
-        executeSql( "update dataelement set vtype='LONG_TEXT' where valuetype='string' and texttype='longText'" );
-
-        executeSql( "update dataelement set vtype='DATE' where valuetype='date'" );
-        executeSql( "update dataelement set vtype='DATETIME' where valuetype='datetime'" );
-        executeSql( "update dataelement set vtype='BOOLEAN' where valuetype='bool'" );
-        executeSql( "update dataelement set vtype='TRUE_ONLY' where valuetype='trueOnly'" );
-        executeSql( "update dataelement set vtype='USERNAME' where valuetype='username'" );
-
-        executeSql( "alter table dataelement drop column valuetype" );
-        executeSql( "alter table dataelement drop column numbertype" );
-        executeSql( "alter table dataelement drop column texttype" );
-
-        executeSql( "update trackedentityattribute set valuetype='TEXT' where valuetype='string'" );
-        executeSql( "update trackedentityattribute set valuetype='PHONE_NUMBER' where valuetype='phoneNumber'" );
-        executeSql( "update trackedentityattribute set valuetype='EMAIL' where valuetype='email'" );
-        executeSql( "update trackedentityattribute set valuetype='NUMBER' where valuetype='number'" );
-        executeSql( "update trackedentityattribute set valuetype='LETTER' where valuetype='letter'" );
-        executeSql( "update trackedentityattribute set valuetype='BOOLEAN' where valuetype='bool'" );
-        executeSql( "update trackedentityattribute set valuetype='TRUE_ONLY' where valuetype='trueOnly'" );
-        executeSql( "update trackedentityattribute set valuetype='DATE' where valuetype='date'" );
-        executeSql( "update trackedentityattribute set valuetype='OPTION_SET' where valuetype='optionSet'" );
-        executeSql( "update trackedentityattribute set valuetype='TRACKER_ASSOCIATE' where valuetype='trackerAssociate'" );
-        executeSql( "update trackedentityattribute set valuetype='USERNAME' where valuetype='users'" );
-    }
-
     public void oauth2()
     {
         // OAuth2

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml	2015-09-04 10:49:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml	2015-09-04 11:23:32 +0000
@@ -22,7 +22,7 @@
 
     <property name="formName" length="230" />
 
-    <property name="valueType" column="vtype" length="50" access="property">
+    <property name="valueType" length="50" access="property">
       <type name="org.hibernate.type.EnumType">
         <param name="enumClass">org.hisp.dhis.common.ValueType</param>
         <param name="useNamed">true</param>