Skip to content

Commit

Permalink
split into two
Browse files Browse the repository at this point in the history
  • Loading branch information
calypsomatic committed Oct 15, 2024
1 parent 08abd65 commit ef2be68
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1007,14 +1007,18 @@ class PostgresAccessPolicyDAO(
}

override def removePolicyGroupsInUse(resourceId: FullyQualifiedResourceId, samRequestContext: SamRequestContext): IO[Unit] = {
removeFromGroupTable(resourceId, samRequestContext)
removeFromGroupTableFlat(resourceId, samRequestContext)
}

private def removeFromGroupTable(resourceId: FullyQualifiedResourceId, samRequestContext: SamRequestContext): IO[Unit] = {
logger.warn("deleting from group_member tables")
val gm = GroupMemberTable.syntax("gm")
val p = PolicyTable.syntax("p")
val gmf = GroupMemberFlatTable.syntax("gmf")

serializableWriteTransaction("removePolicyGroupsInUse", samRequestContext) { implicit session =>
val deleteQuery = samsql"""delete from ${GroupMemberTable as gm} where ${gm.memberGroupId} in
serializableWriteTransaction("removeFromGroupTable", samRequestContext) { implicit session =>
val deleteQuery =
samsql"""delete from ${GroupMemberTable as gm} where ${gm.memberGroupId} in
(select distinct ${gm.result.memberGroupId}
from ${GroupMemberTable as gm}
join ${PolicyTable as p} on ${gm.memberGroupId} = ${p.groupId}
Expand All @@ -1023,8 +1027,14 @@ class PostgresAccessPolicyDAO(
logger.warn(s"deleteQuery: ${deleteQuery.statement}")
deleteQuery.update().apply()
}
}

private def removeFromGroupTableFlat(resourceId: FullyQualifiedResourceId, samRequestContext: SamRequestContext): IO[Unit] = {
logger.warn("deleting from group_member_flat tables")
val p = PolicyTable.syntax("p")
val gmf = GroupMemberFlatTable.syntax("gmf")

serializableWriteTransaction("removePolicyGroupsInUse", samRequestContext) { implicit session =>
serializableWriteTransaction("removeFromGroupTableFlat", samRequestContext) { implicit session =>
val deleteFlatQuery = samsql"""delete from ${GroupMemberFlatTable as gmf} where ${gmf.memberGroupId} in
(select distinct ${gmf.result.memberGroupId}
from ${GroupMemberFlatTable as gmf}
Expand Down

0 comments on commit ef2be68

Please sign in to comment.