Skip to content

Commit

Permalink
Minor updates to DAOs
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek committed Aug 3, 2024
1 parent f9b3c45 commit f96af39
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/app/models/ChangesModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ChangesModel @Inject()(
org <- orgsByGuid.get(app.db.organizationGuid)
fromVersion <- versionsByGuid.get(change.db.fromVersionGuid)
toVersion <- versionsByGuid.get(change.db.toVersionGuid)
changedBy <- usersByGuid.get(change.db.toVersionGuid)
changedBy <- usersByGuid.get(change.db.changedByGuid)
} yield {
Change(
guid = change.guid,
Expand Down
27 changes: 26 additions & 1 deletion dao/spec/psql-apibuilder.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,32 @@
"indexes": [
{ "fields": ["application_guid"] },
{ "fields": ["to_version_guid"] }
],
"foreign_keys": [
{
"fields": ["application_guid", "from_version_guid"],
"references": "versions(application_guid, guid)"
},
{
"fields": ["application_guid", "to_version_guid"],
"references": "versions(application_guid, guid)"
},
{
"fields": ["application_guid"],
"references": "applications"
},
{
"fields": ["from_version_guid"],
"references": "versions"
},
{
"fields": ["to_version_guid"],
"references": "versions"
},
{
"fields": ["changed_by_guid"],
"references": "users"
}
]
}
}
Expand Down Expand Up @@ -782,7 +808,6 @@
"name": "psql",
"value": {
"pkey": "id",
"hash_code": {},
"indexes": [
{ "fields": ["user_guid"] }
]
Expand Down
25 changes: 8 additions & 17 deletions generated/app/db/SessionsDao.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ case object SessionsTable {
override val name: String = "deleted_by_guid"
}

case object HashCode extends Column {
override val name: String = "hash_code"
}

val all: List[Column] = List(Id, UserGuid, ExpiresAt, CreatedAt, CreatedByGuid, UpdatedAt, UpdatedByGuid, DeletedAt, DeletedByGuid, HashCode)
val all: List[Column] = List(Id, UserGuid, ExpiresAt, CreatedAt, CreatedByGuid, UpdatedAt, UpdatedByGuid, DeletedAt, DeletedByGuid)
}
}

Expand All @@ -101,8 +97,7 @@ trait BaseSessionsDao {
| updated_at,
| updated_by_guid::text,
| deleted_at,
| deleted_by_guid::text,
| hash_code
| deleted_by_guid::text
| from public.sessions
|""".stripMargin.stripTrailing
)
Expand Down Expand Up @@ -217,8 +212,7 @@ trait BaseSessionsDao {
anorm.SqlParser.get[org.joda.time.DateTime]("updated_at") ~
anorm.SqlParser.str("updated_by_guid") ~
anorm.SqlParser.get[org.joda.time.DateTime]("deleted_at").? ~
anorm.SqlParser.str("deleted_by_guid").? ~
anorm.SqlParser.long("hash_code") map { case id ~ userGuid ~ expiresAt ~ createdAt ~ createdByGuid ~ updatedAt ~ updatedByGuid ~ deletedAt ~ deletedByGuid ~ hashCode =>
anorm.SqlParser.str("deleted_by_guid").? map { case id ~ userGuid ~ expiresAt ~ createdAt ~ createdByGuid ~ updatedAt ~ updatedByGuid ~ deletedAt ~ deletedByGuid =>
Session(
id = id,
userGuid = java.util.UUID.fromString(userGuid),
Expand All @@ -242,9 +236,9 @@ class SessionsDao @javax.inject.Inject() (override val db: play.api.db.Database)
private val InsertQuery: io.flow.postgresql.Query = {
io.flow.postgresql.Query("""
| insert into public.sessions
| (id, user_guid, expires_at, created_at, created_by_guid, updated_at, updated_by_guid, hash_code)
| (id, user_guid, expires_at, created_at, created_by_guid, updated_at, updated_by_guid)
| values
| ({id}, {user_guid}::uuid, {expires_at}::timestamptz, {created_at}::timestamptz, {created_by_guid}::uuid, {updated_at}::timestamptz, {updated_by_guid}::uuid, {hash_code}::bigint)
| ({id}, {user_guid}::uuid, {expires_at}::timestamptz, {created_at}::timestamptz, {created_by_guid}::uuid, {updated_at}::timestamptz, {updated_by_guid}::uuid)
""".stripMargin)
}

Expand All @@ -254,9 +248,8 @@ class SessionsDao @javax.inject.Inject() (override val db: play.api.db.Database)
| set user_guid = {user_guid}::uuid,
| expires_at = {expires_at}::timestamptz,
| updated_at = {updated_at}::timestamptz,
| updated_by_guid = {updated_by_guid}::uuid,
| hash_code = {hash_code}::bigint
| where id = {id} and sessions.hash_code != {hash_code}::bigint
| updated_by_guid = {updated_by_guid}::uuid
| where id = {id}
""".stripMargin)
}

Expand Down Expand Up @@ -486,7 +479,6 @@ class SessionsDao @javax.inject.Inject() (override val db: play.api.db.Database)
.bind("expires_at", form.expiresAt)
.bind("updated_at", org.joda.time.DateTime.now)
.bind("updated_by_guid", user)
.bind("hash_code", form.hashCode())
}

private def toNamedParameter(
Expand All @@ -498,8 +490,7 @@ class SessionsDao @javax.inject.Inject() (override val db: play.api.db.Database)
anorm.NamedParameter("user_guid", form.userGuid.toString),
anorm.NamedParameter("expires_at", form.expiresAt),
anorm.NamedParameter("updated_at", org.joda.time.DateTime.now),
anorm.NamedParameter("updated_by_guid", user.toString),
anorm.NamedParameter("hash_code", form.hashCode())
anorm.NamedParameter("updated_by_guid", user.toString)
)
}
}

0 comments on commit f96af39

Please sign in to comment.