dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39670
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20091: Table alteror fix. Programinstance.incidentdate was not created. Simpler to let hibernate create ...
------------------------------------------------------------
revno: 20091
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-09-11 15:17:50 +0200
message:
Table alteror fix. Programinstance.incidentdate was not created. Simpler to let hibernate create new columns, then update new columns based on old, then drop old columns.
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/program/hibernate/Program.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.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-09-11 12:58:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java 2015-09-11 13:17:50 +0000
@@ -58,8 +58,6 @@
@Transactional
public void execute()
{
- // domain type
-
executeSql( "update dataelement set domaintype='AGGREGATE' where domaintype='aggregate' or domaintype is null;" );
executeSql( "update dataelement set domaintype='TRACKER' where domaintype='patient';" );
executeSql( "update users set invitation = false where invitation is null" );
@@ -69,10 +67,7 @@
executeSql( "UPDATE programstageinstance SET status='COMPLETED' WHERE status='1';" );
executeSql( "UPDATE programstageinstance SET status='SKIPPED' WHERE status='5';" );
- if( columnExists( "program", "displayonallorgunit" ) )
- {
- executeSql( "ALTER TABLE program DROP COLUMN displayonallorgunit" );
- }
+ executeSql( "ALTER TABLE program DROP COLUMN displayonallorgunit" );
upgradeProgramStageDataElements();
updateValueTypes();
@@ -80,52 +75,32 @@
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'" );
-
- renameColumn( "program", "dateofenrollmentdescription", "enrollmentdatelabel" );
- renameColumn( "program", "dateofincidentdescription", "incidentdatelabel" );
- renameColumn( "programinstance", "dateofincident", "incidentdate" );
-
}
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
- private void renameColumn( String table, String oldColumn, String newColumn )
- {
- if ( columnExists( table, oldColumn ) )
- {
- executeSql( "update " + table + " set " + newColumn + " = " + oldColumn );
- executeSql( "alter table " + table + " drop column " + oldColumn );
- }
- }
-
private void updateValueTypes()
{
executeSql( "alter table dataelement alter column valuetype type varchar(50)" );
- if ( columnExists( "dataelement", "numbertype" ) )
- {
- 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='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( "alter table dataelement drop column numbertype" );
- }
+ executeSql( "alter table dataelement drop column numbertype" );
executeSql( "update dataelement set valuetype='NUMBER' where valuetype='int'" );
- if ( columnExists( "dataelement", "texttype" ) )
- {
- 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='TEXT' where valuetype='string' and texttype='text'" );
+ executeSql( "update dataelement set valuetype='LONG_TEXT' where valuetype='string' and texttype='longText'" );
- executeSql( "alter table dataelement drop column texttype" );
- }
+ executeSql( "alter table dataelement drop column texttype" );
executeSql( "update dataelement set valuetype='TEXT' where valuetype='string'" );
@@ -197,18 +172,4 @@
return false;
}
}
-
- private boolean columnExists( String table, String column )
- {
- try
- {
- return statementManager.getHolder().queryForString(
- "select column_name from information_schema.columns where table_name='" + table + "' and column_name='"
- + column + "'" ) == null ? false : true;
- }
- catch ( Exception ex )
- {
- return false;
- }
- }
}
=== 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-10 11:56:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2015-09-11 13:17:50 +0000
@@ -847,6 +847,14 @@
executeSql( "update chart set completedonly = false where completedonly is null" );
executeSql( "update eventreport set completedonly = false where completedonly is null" );
executeSql( "update eventchart set completedonly = false where completedonly is null" );
+
+ executeSql( "update program set enrollmentdatelabel = dateofenrollmentdescription where enrollmentdatelabel is null" );
+ executeSql( "update program set incidentdatelabel = dateofincidentdescription where incidentdatelabel is null" );
+ executeSql( "update programinstance set incidentdate = dateofincident where incidentdate is null" );
+ executeSql( "alter table programinstance alter column incidentdate set not null" );
+ executeSql( "alter table program drop column dateofenrollmentdescription" );
+ executeSql( "alter table program drop column dateofincidentdescription" );
+ executeSql( "alter table programinstance drop column dateofincident" );
// Remove data mart
executeSql( "drop table aggregateddatasetcompleteness" );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml 2015-09-11 11:54:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml 2015-09-11 13:17:50 +0000
@@ -21,9 +21,9 @@
<property name="version" />
- <property name="enrollmentDateLabel" type="text" />
+ <property name="enrollmentDateLabel" column="enrollmentdatelabel" type="text" />
- <property name="incidentDateLabel" type="text" />
+ <property name="incidentDateLabel" column="incidentdatelabel" type="text" />
<set name="programStages" order-by="sortOrder" cascade="all">
<key column="programid" />
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml 2015-09-11 11:54:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml 2015-09-11 13:17:50 +0000
@@ -16,7 +16,7 @@
<property name="lastUpdated" type="timestamp" />
- <property name="incidentDate" column="incidentDate" not-null="true" />
+ <property name="incidentDate" column="incidentDate" />
<property name="enrollmentDate" column="enrollmentdate" not-null="true" />
@@ -61,9 +61,5 @@
<many-to-one name="organisationUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit" column="organisationunitid"
foreign-key="fk_programinstance_organisationunitid" not-null="false" lazy="false" />
- <!--<many-to-one name="comment" cascade="all"
- class="org.hisp.dhis.trackedentitycomment.TrackedEntityComment"
- column="trackedentitycommentid" foreign-key="fk_programinstance_commentid" />-->
-
</class>
</hibernate-mapping>