Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek committed Jun 4, 2024
1 parent 041ea43 commit 19c232c
Showing 1 changed file with 46 additions and 16 deletions.
62 changes: 46 additions & 16 deletions api/app/util/ProcessDeletes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,66 @@ class ProcessDeletes @Inject() (
def all(): Unit = {
organizations()
applications()
versions()
}

private[util] def organizations(): Unit = {
exec("""
|update applications
| set deleted_at=now(),deleted_by_guid={deleted_by_guid}::uuid
| where deleted_at is null
| and organization_guid in (
| select guid from organizations where deleted_at is not null
| )
|""".stripMargin
)
Seq("applications", "memberships", "membership_requests", "organization_attribute_values", "organization_domains", "subscriptions").foreach { table =>
exec(
s"""
|update $table
| set deleted_at=now(),deleted_by_guid={deleted_by_guid}::uuid
| where deleted_at is null
| and organization_guid in (select guid from organizations where deleted_at is not null)
|""".stripMargin
)
}
Seq("organization_logs").foreach { table =>
exec(
s"""
|delete from $table
| where organization_guid in (select guid from organizations where deleted_at is not null)
|""".stripMargin
)
}
}

private[util] def applications(): Unit = {
Seq("versions", "watches").foreach { table =>
exec(
s"""
|update $table
| set deleted_at=now(),deleted_by_guid={deleted_by_guid}::uuid
| where deleted_at is null
| and application_guid in (select guid from applications where deleted_at is not null)
|""".stripMargin
)
}
}

private[util] def versions(): Unit = {
exec("""
|update versions
| set deleted_at=now(),deleted_by_guid={deleted_by_guid}::uuid
| where deleted_at is null
| and application_guid in (
| select guid from applications where deleted_at is not null
| )
|""".stripMargin
|delete from migrations
| where version_guid in (select guid from versions where deleted_at is not null)
|""".stripMargin
)
Seq("originals", "cache.services").foreach { table =>
exec(
s"""
|update $table
| set deleted_at=now(),deleted_by_guid={deleted_by_guid}::uuid
| where deleted_at is null
| and version_guid in (select guid from versions where deleted_at is not null)
|""".stripMargin
)
}
}

private[this] def exec(q: String): Unit = {
db.withConnection { c =>
Query(q)
.bind("deleted_by_guid", usersDao.AdminUser.guid)
.withDebugging()
.anormSql()
.executeUpdate()(c)
}
Expand Down

0 comments on commit 19c232c

Please sign in to comment.