Skip to content

Commit

Permalink
Cascade org/app soft delete at start of purge
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek committed Jun 18, 2024
1 parent a999608 commit 4d4d72e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions api/app/processor/PurgeDeletedProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class PurgeDeletedProcessor @Inject()(
}

override def processRecord(id: String): ValidatedNec[String, Unit] = {
softDelete(Tables.applications)(_.in("organization_guid", Query("select guid from organizations where deleted_at is not null")))
softDelete(Tables.versions)(_.in("application_guid", Query("select guid from applications where deleted_at is not null")))

debug("PurgeDeletedProcessor starting to delete versions")
deleteAll(Tables.versions) { row =>
debug(s" - version: ${row.pkey}")
Expand Down Expand Up @@ -124,14 +127,18 @@ class PurgeDeletedProcessor @Inject()(
})
}

private[this] def softDelete(table: Table)(filter: Query => Query): Unit = {
exec(
filter(Query(
s"update ${table.qualified} set deleted_at = now() - interval '45 days', deleted_by_guid = {deleted_by_guid}::uuid"
).bind("deleted_by_guid", usersDao.AdminUser.guid)
.and("(deleted_at is null or deleted_at > now() - interval '32 days')")
))
}

private[this] def delete(table: Table)(filter: Query => Query): Unit = {
if (hasDeletedAt(table)) {
exec(
filter(Query(
s"update ${table.qualified} set deleted_at = now() - interval '45 days', deleted_by_guid = {deleted_by_guid}::uuid"
).bind("deleted_by_guid", usersDao.AdminUser.guid)
.and("(deleted_at is null or deleted_at > now() - interval '32 days')")
))
softDelete(table)(filter)
}

exec(
Expand Down

0 comments on commit 4d4d72e

Please sign in to comment.