Chris Werner Rau
07/17/2023, 12:40 PMDaniel Weidensdörfer
07/17/2023, 3:20 PMChris Werner Rau
07/17/2023, 5:34 PMclass KubernetesCluster(
id: EntityID<String>,
) : Entity<String>(id) {
companion object : EntityClass<String, KubernetesCluster>(KubernetesClusterTable)
val name by KubernetesClusterTable.name
1. // val slas by ServiceLevelAgreement referrersOn ServiceLevelAgreementTable.cluster // doesn't work because I also don't have a third table?
2. // val slas by ServiceLevelAgreement via ServiceLevelAgreementTable // doesn't work as I don't have a third table
}
object KubernetesClusterTable : IdTable<String>("kubernetes_cluster") {
override val id = text("id").entityId()
val name = text("name")
}
class ServiceLevelAgreement(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<ServiceLevelAgreement>(ServiceLevelAgreementTable)
val since by ServiceLevelAgreementTable.since
}
object ServiceLevelAgreementTable : IntIdTable("kubernetes_cluster_sla") {
val cluster = reference("cluster_id", KubernetesClusterTable)
val since = date("start_date")
}
And I'm trying to list all SLAs for the KubernetesCluster
Now, when I use the first option, the referrersOn
, I get the following error;
ERROR: operator does not exist: integer = character varying
Which happens because exposed is trying to find the SLA by its ID but it's using the KubernetesCluster.id for this, which of course won't work.
When I try the second option, the via
, I get the following error;
Table does not reference target
Which looks like it's happening because it's trying to find the column in the SLATable which references the SLATable?, see https://github.com/JetBrains/Exposed/blob/main/exposed-dao/src/main/kotlin/org/jetbrains/exposed/dao/InnerTableLink.kt#L42-L44
I've looked through https://github.com/JetBrains/Exposed/wiki/DAO#many-to-one-reference but I can't for the life of me figure out how to do this.Daniel Weidensdörfer
07/17/2023, 5:48 PMChris Werner Rau
07/17/2023, 5:48 PMDaniel Weidensdörfer
07/17/2023, 5:49 PMDaniel Weidensdörfer
07/17/2023, 5:49 PMDaniel Weidensdörfer
07/17/2023, 5:51 PMvar film by StarWarsFilm referencedOn UserRatings.film // use referencedOn for normal references
(copied from the docs)Chris Werner Rau
07/17/2023, 5:52 PMDaniel Weidensdörfer
07/17/2023, 5:52 PMDaniel Weidensdörfer
07/17/2023, 5:56 PMreferencedOn
Chris Werner Rau
07/17/2023, 5:56 PMKubernetesCluster
.all()
.with(
KubernetesCluster::slas,
)
.toList()
Daniel Weidensdörfer
07/17/2023, 6:02 PMobject Children : IntIdTable() {
val parent = reference("parent", Parents)
}
class Child(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Child>(Children)
var parent by Parent referencedOn Children.parent
}
object Parents : IntIdTable() {
val name = varchar("name", 256)
}
class Parent(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Parent>(Parents)
var name by Parents.name
val children by Child referrersOn Children.parent
}
Chris Werner Rau
07/17/2023, 8:05 PMChris Werner Rau
07/17/2023, 8:31 PMwarmUpReferences
the dao goes through https://github.com/JetBrains/Exposed/blob/main/exposed-dao/src/main/kotlin/org/jetbrains/exposed/dao/EntityClass.kt#L383-L389 in the context of the ServiceLevelAgreement$Companion.
The distinctRefIds
are the cluster IDs and it tries to findById
the ServiceLevelAgreement by the cluster id which of course doesn't work and results in the wrong type PG exceptionChris Werner Rau
07/18/2023, 8:28 AMpodman run --rm -it -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=domain --network host postgres
) and run gradle run
inside the directoryDaniel Weidensdörfer
07/18/2023, 8:58 AMChris Werner Rau
07/18/2023, 9:03 AMChris Werner Rau
07/18/2023, 9:05 AMChris Werner Rau
07/18/2023, 9:09 AMorg.h2.jdbc.JdbcSQLSyntaxErrorException: Constraint "PRIMARY KEY | UNIQUE (NAME)" not found; SQL statement:
CREATE TABLE IF NOT EXISTS KUBERNETES_CLUSTER (ID TEXT NOT NULL, CUSTOMER_ID INT NOT NULL, "NAME" TEXT NOT NULL, CLOUD TEXT NOT NULL, CONSTRAINT FK_KUBERNETES_CLUSTER_CUSTOMER_ID__ID FOREIGN KEY (CUSTOMER_ID) REFERENCES CUSTOMER(ID) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT FK_KUBERNETES_CLUSTER_CLOUD__NAME FOREIGN KEY (CLOUD) REFERENCES CLOUD("NAME") ON DELETE RESTRICT ON UPDATE RESTRICT)
But I'm not using h2 anyways, so 😅Daniel Weidensdörfer
07/18/2023, 9:18 AMBut did my reproduction zip fail for you too?I didnt try, I'm not at the postgres/kubernetes stage yet 😄
Chris Werner Rau
07/18/2023, 9:19 AMChris Werner Rau
07/18/2023, 9:24 AMdocker
instead of podman
you can just replace podman
with docker