-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add not-null constraint for column trackedentitytypeid in trackedentity table [DHIS2-15066] #19112
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are having discussion about the approach here (that is the same for organisationunitid column in event and enrollment) and we are trying to avoid to create dummy data that are likely entering the DB and never being deleted.
I think we should fix this the same way in all the places where we found it.
As soon as we have a strategy we should go back to this PR and see what we should do.
Quality Gate passedIssues Measures |
@@ -521,14 +521,14 @@ private List<Enrollment> getEnrollments() { | |||
} | |||
|
|||
private TrackedEntity getTrackedEntityA() { | |||
TrackedEntity te = createTrackedEntity(organisationUnitA); | |||
TrackedEntity te = createTrackedEntity(organisationUnitA, createTrackedEntityType('I')); | |||
te.setTrackedEntityType(trackedEntityTypeA); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTrackedEntityType can be removed
te.setTrackedEntityType(trackedEntityTypeA); | ||
|
||
return te; | ||
} | ||
|
||
private TrackedEntity getTrackedEntityB() { | ||
TrackedEntity te = createTrackedEntity(organisationUnitB); | ||
TrackedEntity te = createTrackedEntity(organisationUnitB, createTrackedEntityType('F')); | ||
te.setTrackedEntityType(trackedEntityTypeB); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTrackedEntityType can be removed
femaleA.setTrackedEntityType(trackedEntityType); | ||
femaleB.setTrackedEntityType(trackedEntityType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTrackedEntityType
@@ -320,7 +322,8 @@ private TrackedEntity teWithDeleteEnrollments() { | |||
} | |||
|
|||
private TrackedEntity teWithEnrollments() { | |||
TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); | |||
TrackedEntity trackedEntity = | |||
createTrackedEntity(organisationUnit, createTrackedEntityType('R')); | |||
trackedEntity.setUid(TE_ID.getValue()); | |||
trackedEntity.setEnrollments(Sets.newHashSet(new Enrollment())); | |||
trackedEntity.setTrackedEntityType(trackedEntityType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTrackedEntityType
@@ -311,7 +312,8 @@ private TrackedEntity teWithDeleteEnrollments() { | |||
Enrollment enrollment = new Enrollment(); | |||
enrollment.setDeleted(true); | |||
|
|||
TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); | |||
TrackedEntity trackedEntity = | |||
createTrackedEntity(organisationUnit, createTrackedEntityType('B')); | |||
trackedEntity.setUid(TE_ID.getValue()); | |||
trackedEntity.setEnrollments(Sets.newHashSet(enrollment)); | |||
trackedEntity.setTrackedEntityType(trackedEntityType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTrackedEntityType
@@ -486,7 +486,8 @@ void verifySuccessEventValidationWhenEventHasNoOrgUnitAssigned() { | |||
} | |||
|
|||
private TrackedEntity teWithNoEnrollments() { | |||
TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); | |||
TrackedEntity trackedEntity = | |||
createTrackedEntity(organisationUnit, createTrackedEntityType('E')); | |||
trackedEntity.setUid(TE_ID.getValue()); | |||
trackedEntity.setEnrollments(Sets.newHashSet()); | |||
trackedEntity.setTrackedEntityType(trackedEntityType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTrackedEntityType
@@ -389,7 +389,8 @@ void verifyValidationFailsForEnrollmentDeletionAndUserWithoutTrackedEntityTypeRe | |||
} | |||
|
|||
private TrackedEntity teWithNoEnrollments() { | |||
TrackedEntity trackedEntity = createTrackedEntity(organisationUnit); | |||
TrackedEntity trackedEntity = | |||
createTrackedEntity(organisationUnit, createTrackedEntityType('C')); | |||
trackedEntity.setUid(TE_ID.getValue()); | |||
trackedEntity.setEnrollments(Sets.newHashSet()); | |||
trackedEntity.setTrackedEntityType(trackedEntityType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTrackedEntityType
@@ -263,7 +263,7 @@ private TrackedEntityType trackedEntityType(String uid, char uniqueChar) { | |||
} | |||
|
|||
private TrackedEntity trackedEntity(UID uid, TrackedEntityType type, OrganisationUnit orgUnit) { | |||
TrackedEntity te = createTrackedEntity(orgUnit); | |||
TrackedEntity te = createTrackedEntity(orgUnit, createTrackedEntityType('R')); | |||
te.setUid(uid.getValue()); | |||
te.setTrackedEntityType(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTrackedEntityType
WHERE trackedentitytypeid IS NULL | ||
) | ||
LOOP | ||
UPDATE trackedentity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we shouldn't update any record.
We should only apply the constraint.
The we can suggest such a script in the migration notes
SELECT COUNT(*) INTO inconsistent_records_count FROM trackedentity WHERE trackedentitytypeid IS NULL; | ||
|
||
IF inconsistent_records_count = 0 THEN | ||
ALTER TABLE trackedentity ALTER COLUMN trackedentitytypeid SET NOT NULL; | ||
ELSE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is a little bit redundant.
You can apply the constraint and if it fails then you raise the exception.
DHIS2-15066
createTrackedEntity
method signature inTestBase.java
to make sure user provide a non-nullTrackedEntityType
toTrackedEntity
.