Skip to content

Commit

Permalink
CE-18 and CE-19 - Rename timestamp columns (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
barrfalk authored Oct 16, 2023
1 parent 458c7c6 commit 7019568
Show file tree
Hide file tree
Showing 81 changed files with 10,999 additions and 10,843 deletions.
4 changes: 2 additions & 2 deletions backend/db/migrations/R__Configuration-values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ insert
long_description,
active_ind,
create_user_id,
create_timestamp,
create_utc_timestamp,
update_user_id,
update_timestamp)
update_utc_timestamp)
values ('DFLTPAGNUM',
'50',
'The default number of rows per page when displaying lists within the application.',
Expand Down
564 changes: 282 additions & 282 deletions backend/db/migrations/R__Create-Test-Data.sql

Large diffs are not rendered by default.

3,864 changes: 1,932 additions & 1,932 deletions backend/db/migrations/R__WebEOC-July-ERS-complaints.sql

Large diffs are not rendered by default.

16,728 changes: 8,364 additions & 8,364 deletions backend/db/migrations/R__WebEOC-July-HWCR-complaints.sql

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions backend/db/migrations/V0.9.1__CE-19.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
alter table complaint
rename incident_reported_datetime to incident_reported_utc_timestmp;

-- rename audit timestamp columns
alter table geo_org_unit_type_code
rename create_timestamp to create_utc_timestamp;

alter table geo_org_unit_type_code rename update_timestamp to update_utc_timestamp;

alter table geo_organization_unit_code
rename create_timestamp to create_utc_timestamp;

alter table geo_organization_unit_code rename update_timestamp to update_utc_timestamp;

alter table office
rename create_timestamp to create_utc_timestamp;

alter table office rename update_timestamp to update_utc_timestamp;

alter table person
rename create_timestamp to create_utc_timestamp;

alter table person rename update_timestamp to update_utc_timestamp;

alter table officer
rename create_timestamp to create_utc_timestamp;

alter table officer rename update_timestamp to update_utc_timestamp;

alter table complaint
rename create_timestamp to create_utc_timestamp;

alter table complaint rename update_timestamp to update_utc_timestamp;

alter table agency_code
rename create_timestamp to create_utc_timestamp;

alter table agency_code rename update_timestamp to update_utc_timestamp;

alter table complaint_status_code
rename create_timestamp to create_utc_timestamp;

alter table complaint_status_code rename update_timestamp to update_utc_timestamp;

alter table geo_org_unit_structure
rename create_timestamp to create_utc_timestamp;

alter table geo_org_unit_structure rename update_timestamp to update_utc_timestamp;

alter table allegation_complaint
rename create_timestamp to create_utc_timestamp;

alter table allegation_complaint rename update_timestamp to update_utc_timestamp;

alter table violation_code
rename create_timestamp to create_utc_timestamp;

alter table violation_code rename update_timestamp to update_utc_timestamp;

alter table hwcr_complaint
rename create_timestamp to create_utc_timestamp;

alter table hwcr_complaint rename update_timestamp to update_utc_timestamp;

alter table species_code
rename create_timestamp to create_utc_timestamp;

alter table species_code rename update_timestamp to update_utc_timestamp;

alter table hwcr_complaint_nature_code
rename create_timestamp to create_utc_timestamp;

alter table hwcr_complaint_nature_code rename update_timestamp to update_utc_timestamp;

alter table attractant_code
rename create_timestamp to create_utc_timestamp;

alter table attractant_code rename update_timestamp to update_utc_timestamp;

alter table person_complaint_xref
rename create_timestamp to create_utc_timestamp;

alter table person_complaint_xref rename update_timestamp to update_utc_timestamp;

alter table person_complaint_xref_code
rename create_timestamp to create_utc_timestamp;

alter table person_complaint_xref_code rename update_timestamp to update_utc_timestamp;

alter table attractant_hwcr_xref
rename create_timestamp to create_utc_timestamp;

alter table attractant_hwcr_xref rename update_timestamp to update_utc_timestamp;

alter table configuration
rename create_timestamp to create_utc_timestamp;

alter table configuration rename update_timestamp to update_utc_timestamp;

CREATE OR REPLACE FUNCTION audit_history() RETURNS trigger AS $BODY$
DECLARE

target_history_table TEXT;
target_pk TEXT;

BEGIN
target_history_table := TG_ARGV[0];
target_pk := TG_ARGV[1];

IF TG_OP ='INSERT' THEN

-- Don't trust the caller not to manipulate any of these fields
NEW.create_utc_timestamp := current_timestamp; -- create timestamp must be the current time
NEW.update_utc_timestamp := current_timestamp; -- update timestamp must be the current time
NEW.update_user_id := NEW.create_user_id; -- the update user must be the same as the create user

EXECUTE
format(
'INSERT INTO %I (target_row_id, operation_type, operation_user_id, data_after_executed_operation) VALUES ($1.%I, ''I'', $1.create_user_id, to_jsonb($1))', target_history_table, target_pk
)
USING NEW;
RETURN NEW;

ELSIF TG_OP = 'UPDATE' THEN

-- Don't trust the caller not to manipulate any of these fields
NEW.update_utc_timestamp := current_timestamp; -- update timestamp must be the current time
NEW.create_user_id := OLD.create_user_id; -- create userId can't be altered
NEW.create_utc_timestamp := OLD.create_utc_timestamp; -- update timestamp can't be altered

EXECUTE
format(
'INSERT INTO %I (target_row_id, operation_type, operation_user_id, data_after_executed_operation) VALUES ($1.%I, ''U'', $1.update_user_id, to_jsonb($1))', target_history_table, target_pk
)
USING NEW;
RETURN NEW;

ELSIF TG_OP = 'DELETE' THEN

EXECUTE
format(
'INSERT INTO %I (target_row_id, operation_type) VALUES ($1.%I, ''D'')', target_history_table, target_pk
)
USING OLD;
RETURN OLD;

END IF;
END;
$BODY$
LANGUAGE plpgsql;
4 changes: 2 additions & 2 deletions backend/src/v1/agency_code/dto/agency_code.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class AgencyCodeDto
example: "2003-04-12 04:05:06",
description: "The timestamp when the agency was created",
})
create_timestamp: Date;
create_utc_timestamp: Date;

@ApiProperty({
example: "IDIR\mburns",
Expand All @@ -43,5 +43,5 @@ export class AgencyCodeDto
example: "2003-04-12 04:05:06",
description: "The timestamp when the agency was last updated",
})
update_timestamp: Date;
update_utc_timestamp: Date;
}
4 changes: 2 additions & 2 deletions backend/src/v1/agency_code/entities/agency_code.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class AgencyCode
description: "The timestamp when the agency was created",
})
@Column()
create_timestamp: Date;
create_utc_timestamp: Date;

@ApiProperty({
example: "IDIR\mburns",
Expand All @@ -54,7 +54,7 @@ export class AgencyCode
description: "The timestamp when the agency was last updated",
})
@Column()
update_timestamp: Date;
update_utc_timestamp: Date;

constructor(agency_code?:string) {
this.agency_code = agency_code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ describe("AllegationComplaintService", () => {
});

it("should return an array of complaints", async () => {
const complaints = await service.findAll('incident_reported_datetime', 'DESC');
const complaints = await service.findAll('incident_reported_utc_timestmp', 'DESC');
expect(complaints).toEqual(allegationComplaintArray);
});

Expand Down
28 changes: 14 additions & 14 deletions backend/src/v1/allegation_complaint/allegation_complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class AllegationComplaintService {

const createAllegationComplaintDto: CreateAllegationComplaintDto = JSON.parse(allegationComplaint);
createAllegationComplaintDto.allegation_complaint_guid = randomUUID();
createAllegationComplaintDto.update_timestamp = createAllegationComplaintDto.create_timestamp = new Date();
createAllegationComplaintDto.update_utc_timestamp = createAllegationComplaintDto.create_utc_timestamp = new Date();
let newAllegationComplaintString;
try {
const complaint: Complaint = await this.complaintService.create(
Expand Down Expand Up @@ -96,9 +96,9 @@ export class AllegationComplaintService {
? "allegation_complaint."
: "complaint_identifier.";
const sortString =
sortColumn !== "update_timestamp"
sortColumn !== "update_utc_timestamp"
? sortTable + sortColumn
: "GREATEST(complaint_identifier.update_timestamp, allegation_complaint.update_timestamp)";
: "GREATEST(complaint_identifier.update_utc_timestamp, allegation_complaint.update_utc_timestamp)";
return this.allegationComplaintsRepository
.createQueryBuilder("allegation_complaint")
.leftJoinAndSelect(
Expand Down Expand Up @@ -135,8 +135,8 @@ export class AllegationComplaintService {

.orderBy(sortString, sortOrderString)
.addOrderBy(
"complaint_identifier.incident_reported_datetime",
sortColumn === "incident_reported_datetime" ? sortOrderString : "DESC"
"complaint_identifier.incident_reported_utc_timestmp",
sortColumn === "incident_reported_utc_timestmp" ? sortOrderString : "DESC"
)
.getMany();
}
Expand Down Expand Up @@ -174,13 +174,13 @@ export class AllegationComplaintService {
sortTable = "person.";
}
const sortString =
sortColumn !== "update_timestamp"
sortColumn !== "update_utc_timestamp"
? sortTable + sortColumn
: "_update_timestamp";
: "_update_utc_timestamp";

const queryBuilder = this.allegationComplaintsRepository
.createQueryBuilder("allegation_complaint")
.addSelect("GREATEST(complaint_identifier.update_timestamp, allegation_complaint.update_timestamp)","_update_timestamp")
.addSelect("GREATEST(complaint_identifier.update_utc_timestamp, allegation_complaint.update_utc_timestamp)","_update_utc_timestamp")
.leftJoinAndSelect(
"allegation_complaint.complaint_identifier",
"complaint_identifier"
Expand Down Expand Up @@ -217,8 +217,8 @@ export class AllegationComplaintService {
)
.orderBy(sortString, sortOrderString)
.addOrderBy(
"complaint_identifier.incident_reported_datetime",
sortColumn === "incident_reported_datetime" ? sortOrderString : "DESC"
"complaint_identifier.incident_reported_utc_timestmp",
sortColumn === "incident_reported_utc_timestmp" ? sortOrderString : "DESC"
);
if (community !== null && community !== undefined && community !== "") {
queryBuilder.andWhere("cos_geo_org_unit.area_code = :Community", {
Expand Down Expand Up @@ -267,7 +267,7 @@ export class AllegationComplaintService {
incidentReportedStart !== ""
) {
queryBuilder.andWhere(
"complaint_identifier.incident_reported_datetime >= :IncidentReportedStart",
"complaint_identifier.incident_reported_utc_timestmp >= :IncidentReportedStart",
{ IncidentReportedStart: incidentReportedStart }
);
}
Expand All @@ -277,7 +277,7 @@ export class AllegationComplaintService {
incidentReportedEnd !== ""
) {
queryBuilder.andWhere(
"complaint_identifier.incident_reported_datetime <= :IncidentReportedEnd",
"complaint_identifier.incident_reported_utc_timestmp <= :IncidentReportedEnd",
{ IncidentReportedEnd: incidentReportedEnd }
);
}
Expand Down Expand Up @@ -393,7 +393,7 @@ export class AllegationComplaintService {
incidentReportedStart !== ""
) {
queryBuilder.andWhere(
"complaint_identifier.incident_reported_datetime >= :IncidentReportedStart",
"complaint_identifier.incident_reported_utc_timestmp >= :IncidentReportedStart",
{ IncidentReportedStart: incidentReportedStart }
);
}
Expand All @@ -403,7 +403,7 @@ export class AllegationComplaintService {
incidentReportedEnd !== ""
) {
queryBuilder.andWhere(
"complaint_identifier.incident_reported_datetime <= :IncidentReportedEnd",
"complaint_identifier.incident_reported_utc_timestmp <= :IncidentReportedEnd",
{ IncidentReportedEnd: incidentReportedEnd }
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class AllegationComplaintDto
example: "2003-04-12 04:05:06",
description: "The timestamp when the violation was created",
})
create_timestamp: Date;
create_utc_timestamp: Date;

@ApiProperty({
example: "IDIR\mburns",
Expand All @@ -51,5 +51,5 @@ export class AllegationComplaintDto
example: "2003-04-12 04:05:06",
description: "The timestamp when the violation was last updated",
})
update_timestamp: Date;
update_utc_timestamp: Date;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class CreateAllegationComplaintDto extends PickType(AllegationComplaintDt
"observed_ind",
"suspect_witnesss_dtl_text",
"create_user_id",
"create_timestamp",
"create_utc_timestamp",
"update_user_id",
"update_timestamp"
"update_utc_timestamp"
] as const) {}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class AllegationComplaint
description: "The timestamp when the violation was created",
})
@Column()
create_timestamp: Date;
create_utc_timestamp: Date;

@ApiProperty({
example: "IDIR\mburns",
Expand All @@ -66,18 +66,18 @@ export class AllegationComplaint
description: "The timestamp when the violation was last updated",
})
@Column()
update_timestamp: Date;
update_utc_timestamp: Date;

constructor(complaint_identifier?: Complaint, violation_code?: ViolationCode, in_progress_ind?: boolean, observed_ind?: boolean, suspect_witnesss_dtl_text?: string,
create_user_id?: string, create_timestamp?: Date, update_user_id?: string, update_timestamp?: Date) {
create_user_id?: string, create_utc_timestamp?: Date, update_user_id?: string, update_utc_timestamp?: Date) {
this.complaint_identifier = complaint_identifier;
this.violation_code = violation_code;
this.in_progress_ind = in_progress_ind;
this.observed_ind = observed_ind;
this.suspect_witnesss_dtl_text = suspect_witnesss_dtl_text;
this.create_user_id = create_user_id;
this.create_timestamp = create_timestamp;
this.create_utc_timestamp = create_utc_timestamp;
this.update_user_id = update_user_id;
this.update_timestamp = update_timestamp;
this.update_utc_timestamp = update_utc_timestamp;
}
}
4 changes: 2 additions & 2 deletions backend/src/v1/attractant_code/dto/attractant_code.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class AttractantCodeDto
example: "2003-04-12 04:05:06",
description: "The timestamp when the attractant code was created. The timestamp is stored in UTC with no Offset.",
})
create_timestamp: Date;
create_utc_timestamp: Date;

@ApiProperty({
example: "IDIR\mburns",
Expand All @@ -46,5 +46,5 @@ export class AttractantCodeDto
example: "2003-04-12 04:05:06",
description: "The timestamp when the attractant code was updated. The timestamp is stored in UTC with no Offset.",
})
update_timestamp: Date;
update_utc_timestamp: Date;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class AttractantCode
description: "The timestamp when the attractant code was created. The timestamp is stored in UTC with no Offset.",
})
@Column()
create_timestamp: Date;
create_utc_timestamp: Date;

@ApiProperty({
example: "IDIR\mburns",
Expand All @@ -59,7 +59,7 @@ export class AttractantCode
description: "The timestamp when the attractant code was updated. The timestamp is stored in UTC with no Offset.",
})
@Column()
update_timestamp: Date;
update_utc_timestamp: Date;

constructor(attractant_code?:string) {
this.attractant_code = attractant_code;
Expand Down
Loading

0 comments on commit 7019568

Please sign in to comment.