cleanup OccupancyTypePrints table

deepsource-autofix-76c6eb20
Dan Gowans 2022-12-15 12:52:18 -05:00
parent 40c3761d7c
commit e9240b486b
2 changed files with 30 additions and 0 deletions

View File

@ -134,8 +134,20 @@ export const cleanupDatabase = (requestSession) => {
.prepare("delete from OccupancyTypeFields where recordDelete_timeMillis <= ?" + .prepare("delete from OccupancyTypeFields where recordDelete_timeMillis <= ?" +
" and occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields)") " and occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields)")
.run(recordDelete_timeMillisMin).changes; .run(recordDelete_timeMillisMin).changes;
inactivedRecordCount += database
.prepare("update OccupancyTypePrints" +
" set recordDelete_userName = ?," +
" recordDelete_timeMillis = ?" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId in (select occupancyTypeId from OccupancyTypes where recordDelete_timeMillis is not null)")
.run(requestSession.user.userName, rightNowMillis).changes;
purgedRecordCount += database
.prepare("delete from OccupancyTypePrints where recordDelete_timeMillis <= ?")
.run(recordDelete_timeMillisMin).changes;
purgedRecordCount += database purgedRecordCount += database
.prepare("delete from OccupancyTypes where recordDelete_timeMillis <= ?" + .prepare("delete from OccupancyTypes where recordDelete_timeMillis <= ?" +
" and occupancyTypeId not in (select occupancyTypeId from OccupancyTypeFields)" +
" and occupancyTypeId not in (select occupancyTypeId from OccupancyTypePrints)" +
" and occupancyTypeId not in (select occupancyTypeId from LotOccupancies)" + " and occupancyTypeId not in (select occupancyTypeId from LotOccupancies)" +
" and occupancyTypeId not in (select occupancyTypeId from Fees)") " and occupancyTypeId not in (select occupancyTypeId from Fees)")
.run(recordDelete_timeMillisMin).changes; .run(recordDelete_timeMillisMin).changes;

View File

@ -231,11 +231,29 @@ export const cleanupDatabase = (requestSession: recordTypes.PartialSession) => {
) )
.run(recordDelete_timeMillisMin).changes; .run(recordDelete_timeMillisMin).changes;
// Occupancy Type Prints
inactivedRecordCount += database
.prepare(
"update OccupancyTypePrints" +
" set recordDelete_userName = ?," +
" recordDelete_timeMillis = ?" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId in (select occupancyTypeId from OccupancyTypes where recordDelete_timeMillis is not null)"
)
.run(requestSession.user.userName, rightNowMillis).changes;
purgedRecordCount += database
.prepare("delete from OccupancyTypePrints where recordDelete_timeMillis <= ?")
.run(recordDelete_timeMillisMin).changes;
// Occupancy Types // Occupancy Types
purgedRecordCount += database purgedRecordCount += database
.prepare( .prepare(
"delete from OccupancyTypes where recordDelete_timeMillis <= ?" + "delete from OccupancyTypes where recordDelete_timeMillis <= ?" +
" and occupancyTypeId not in (select occupancyTypeId from OccupancyTypeFields)" +
" and occupancyTypeId not in (select occupancyTypeId from OccupancyTypePrints)" +
" and occupancyTypeId not in (select occupancyTypeId from LotOccupancies)" + " and occupancyTypeId not in (select occupancyTypeId from LotOccupancies)" +
" and occupancyTypeId not in (select occupancyTypeId from Fees)" " and occupancyTypeId not in (select occupancyTypeId from Fees)"
) )