dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #27447
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13678: Tracker, program attribute/identifiertype upgrade script
------------------------------------------------------------
revno: 13678
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-01-09 17:13:26 +0100
message:
Tracker, program attribute/identifiertype upgrade script
modified:
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java
dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java
dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java
--
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-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2014-01-09 15:34:25 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2014-01-09 16:13:26 +0000
@@ -44,6 +44,7 @@
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.patient.PatientAttribute;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageService;
@@ -103,6 +104,9 @@
@Autowired
private JdbcTemplate jdbcTemplate;
+ @Autowired
+ private StatementBuilder statementBuilder;
+
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@@ -292,10 +296,8 @@
executeSql( "UPDATE patientattribute SET displayInListNoProgram=false WHERE displayInListNoProgram is null" );
executeSql( "UPDATE patientidentifiertype SET displayInListNoProgram=false WHERE displayInListNoProgram is null" );
-
- executeSql( "ALTER TABLE patientattribute DROP COLUMN displayedInList" );
- executeSql( "ALTER TABLE patientidentifiertype DROP COLUMN personDisplayName" );
+ updateProgramAttributes();
}
// -------------------------------------------------------------------------
@@ -304,15 +306,23 @@
private void updateProgramAttributes()
{
- executeSql( "INSERT INTO program_attributes (programattributeid, sort_order, displayinlist ) "
- + "SELECT pp.patientattributeid, displayedInList, pp.sort_order FROM program_patientattributes pp "
- + "INNER JOIN patientattribute pa ON pp.patientattributeid=pa.patientattributeid" );
+ String autoIncrVal = statementBuilder.getAutoIncrementValue();
+
+ String attributeSql = "INSERT INTO program_attributes (programattributeid, attributeid, sort_order, displayinlist, programid) "
+ + "SELECT " + autoIncrVal + ", pp.patientattributeid, pp.sort_order, false, pp.programid "
+ + "FROM program_patientattributes pp";
+ executeSql( attributeSql );
+
+ String identifierSql = "INSERT INTO program_identifiertypes (programidentifiertypeid, identifiertypeid, sort_order, displayinlist, programid) "
+ + "SELECT " + autoIncrVal + ", pp.patientidentifiertypeid, pp.sort_order, false, pp.programid "
+ + "FROM program_patientidentifiertypes pp";
+ executeSql( identifierSql );
+
executeSql( "DROP TABLE program_patientattributes" );
+ executeSql( "DROP TABLE program_patientidentifiertypes" );
- executeSql( "INSERT INTO program_identifierTypes (programid, patientidentifiertypeid, displayedInList, sort_order ) "
- + "SELECT programid, pp.patientidentifiertypeid, personDisplayName, pp.sort_order FROM program_patientidentifiertypes pp "
- + "INNER JOIN patientidentifiertype pi ON pp.patientidentifiertypeid=pi.patientidentifiertypeid" );
- executeSql( "DROP TABLE program_patientidentifiertypes" );
+ executeSql( "ALTER TABLE patientattribute DROP COLUMN displayedInList" );
+ executeSql( "ALTER TABLE patientidentifiertype DROP COLUMN personDisplayName" );
}
private void updateUid()
=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java 2014-01-06 17:25:34 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java 2014-01-09 16:13:26 +0000
@@ -85,6 +85,12 @@
String limitRecord( int offset, int limit );
/**
+ * Returns the value to use in insert statements for auto-increment columns.
+ * @return value to use in insert statements for auto-increment columns.
+ */
+ String getAutoIncrementValue();
+
+ /**
* Returns statement for vacuum and analyze operations for a table. Returns
* null if such statement is not relevant.
*
=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java 2014-01-06 17:25:34 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java 2014-01-09 16:13:26 +0000
@@ -69,6 +69,12 @@
}
@Override
+ public String getAutoIncrementValue()
+ {
+ return "null";
+ }
+
+ @Override
public String getPeriodIdentifierStatement( Period period )
{
return
=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java 2013-11-18 13:30:37 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java 2014-01-09 16:13:26 +0000
@@ -53,6 +53,12 @@
{
return "vacuum analyze " + table + ";";
}
+
+ @Override
+ public String getAutoIncrementValue()
+ {
+ return "nextval('hibernate_sequence')";
+ }
@Override
public String getTableOptions( boolean autoVacuum )