diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java index 50bf484bddb9..e33ad0454aac 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java @@ -91,6 +91,7 @@ public class JdbcOwnershipAnalyticsTableManager extends AbstractEventJdbcTableMa AnalyticsTableColumn.builder() .name("teuid") .dataType(CHARACTER_11) + .nullable(NOT_NULL) .selectExpression("te.uid") .build(), AnalyticsTableColumn.builder() @@ -250,16 +251,17 @@ private String getInputSql(Program program) { \sfrom (\ select h.trackedentityid, '${historyTableId}' as startdate, h.enddate as enddate, h.organisationunitid \ from ${programownershiphistory} h \ - where h.programid=${programId} \ + where h.programid = ${programId} \ and h.organisationunitid is not null \ union \ select o.trackedentityid, '${trackedEntityOwnTableId}' as startdate, null as enddate, o.organisationunitid \ from ${trackedentityprogramowner} o \ - where o.programid=${programId} \ + where o.programid = ${programId} \ and exists (\ select 1 from ${programownershiphistory} p \ where o.trackedentityid = p.trackedentityid \ - and p.programid=${programId} and p.organisationunitid is not null)) a \ + and p.programid = ${programId} \ + and p.organisationunitid is not null)) a \ inner join ${trackedentity} te on a.trackedentityid = te.trackedentityid \ inner join ${organisationunit} ou on a.organisationunitid = ou.organisationunitid \ left join analytics_rs_orgunitstructure ous on a.organisationunitid = ous.organisationunitid \ diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManagerTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManagerTest.java index b399999ff371..62de96dba85d 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManagerTest.java @@ -278,14 +278,16 @@ void testPopulateTable() throws SQLException { select te.uid,a.startdate,a.enddate,ou.uid from (\ select h.trackedentityid, '1001-01-01' as startdate, h.enddate as enddate, h.organisationunitid \ from "programownershiphistory" h \ - where h.programid=0 and h.organisationunitid is not null \ + where h.programid = 0 \ + and h.organisationunitid is not null \ union \ select o.trackedentityid, '2002-02-02' as startdate, null as enddate, o.organisationunitid \ from "trackedentityprogramowner" o \ - where o.programid=0 \ + where o.programid = 0 \ and exists (select 1 from "programownershiphistory" p \ where o.trackedentityid = p.trackedentityid \ - and p.programid=0 and p.organisationunitid is not null)\ + and p.programid = 0 \ + and p.organisationunitid is not null)\ ) a \ inner join "trackedentity" te on a.trackedentityid = te.trackedentityid \ inner join "organisationunit" ou on a.organisationunitid = ou.organisationunitid \ diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramOwnershipHistory.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramOwnershipHistory.hbm.xml index e7e469656c0c..6365e268e39e 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramOwnershipHistory.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramOwnershipHistory.hbm.xml @@ -14,13 +14,11 @@ - + - + diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityProgramOwner.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityProgramOwner.hbm.xml index bcb0104a0b40..9f31483898a3 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityProgramOwner.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityProgramOwner.hbm.xml @@ -11,22 +11,20 @@ - + + + column="programid" not-null="true" foreign-key="fk_trackedentityprogramowner_programid" + lazy="false" unique-key="uk_tei_program" /> - + diff --git a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilder.java b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilder.java index be764f22151e..a94a0b299df8 100644 --- a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilder.java +++ b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilder.java @@ -125,9 +125,13 @@ public String dataTypeGeometryPoint() { return "String"; } + /** + * ClickHouse JSON data type is in beta and is not yet production-ready. Check back and enable + * JSON when available. + */ @Override public String dataTypeJson() { - return "JSON"; + return "String"; } // Index functions diff --git a/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilderTest.java b/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilderTest.java index b2b04e284bce..96bd70b71a7b 100644 --- a/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilderTest.java +++ b/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilderTest.java @@ -101,6 +101,7 @@ private Table getTableD() { void testDataTypes() { assertEquals("Float64", sqlBuilder.dataTypeDouble()); assertEquals("DateTime64(3)", sqlBuilder.dataTypeTimestamp()); + assertEquals("String", sqlBuilder.dataTypeJson()); } // Index types @@ -279,7 +280,7 @@ void testCreateTableA() { String expected = """ create table "immunization" ("id" Int64 not null,"data" String not null,\ - "period" String not null,"created" DateTime64(3) null,"user" JSON null,\ + "period" String not null,"created" DateTime64(3) null,"user" String null,\ "value" Float64 null) \ engine = MergeTree() \ order by ("id");"""; diff --git a/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/DorisSqlBuilderTest.java b/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/DorisSqlBuilderTest.java index 2d2e57e98081..141fdcc90c1a 100644 --- a/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/DorisSqlBuilderTest.java +++ b/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/DorisSqlBuilderTest.java @@ -86,6 +86,7 @@ private Table getTableC() { void testDataTypes() { assertEquals("double", sqlBuilder.dataTypeDouble()); assertEquals("datetime", sqlBuilder.dataTypeTimestamp()); + assertEquals("json", sqlBuilder.dataTypeJson()); } // Index types diff --git a/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/PostgreSqlBuilderTest.java b/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/PostgreSqlBuilderTest.java index 8c4516f901cf..a0cd4e5d3953 100644 --- a/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/PostgreSqlBuilderTest.java +++ b/dhis-2/dhis-support/dhis-support-sql/src/test/java/org/hisp/dhis/db/sql/PostgreSqlBuilderTest.java @@ -117,6 +117,7 @@ private Table getTableC() { void testDataTypes() { assertEquals("double precision", sqlBuilder.dataTypeDouble()); assertEquals("geometry", sqlBuilder.dataTypeGeometry()); + assertEquals("jsonb", sqlBuilder.dataTypeJson()); } // Index types