From e9240b486b5c08e07598d7ee5521c5c473b42c55 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Thu, 15 Dec 2022 12:52:18 -0500 Subject: [PATCH] cleanup OccupancyTypePrints table --- helpers/lotOccupancyDB/cleanupDatabase.js | 12 ++++++++++++ helpers/lotOccupancyDB/cleanupDatabase.ts | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/helpers/lotOccupancyDB/cleanupDatabase.js b/helpers/lotOccupancyDB/cleanupDatabase.js index 8648d396..b6512d4f 100644 --- a/helpers/lotOccupancyDB/cleanupDatabase.js +++ b/helpers/lotOccupancyDB/cleanupDatabase.js @@ -134,8 +134,20 @@ export const cleanupDatabase = (requestSession) => { .prepare("delete from OccupancyTypeFields where recordDelete_timeMillis <= ?" + " and occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields)") .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 .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 Fees)") .run(recordDelete_timeMillisMin).changes; diff --git a/helpers/lotOccupancyDB/cleanupDatabase.ts b/helpers/lotOccupancyDB/cleanupDatabase.ts index a93f73bb..9c9c6420 100644 --- a/helpers/lotOccupancyDB/cleanupDatabase.ts +++ b/helpers/lotOccupancyDB/cleanupDatabase.ts @@ -231,11 +231,29 @@ export const cleanupDatabase = (requestSession: recordTypes.PartialSession) => { ) .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 purgedRecordCount += database .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 Fees)" )