Skip to content

Commit 87a89d1

Browse files
committed
components: Fix checking PostgreSQL driver version
1 parent ea86618 commit 87a89d1

File tree

1 file changed

+12
-3
lines changed
  • BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/components/repositories

1 file changed

+12
-3
lines changed

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/components/repositories/ComponentRepository.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,18 @@ internal class ComponentRepository(
7474
}
7575

7676
// The 42.7.5 driver is required for byte[] support in setObject
77-
check(metadata.driverVersion >= "42.7.5") {
78-
"Using components require a version of the PostgreSQL driver higher or equal to 42.7.5"
77+
val driverVersion = metadata.driverVersion
78+
val versionComponents = driverVersion.split('.').mapNotNull { it.toIntOrNull() }
79+
if (versionComponents.size != 3) {
80+
return logger.warn { "Unexpected PostgreSQL driver version: $driverVersion ; skipping check" }
7981
}
82+
83+
val (major, minor, patch) = versionComponents
84+
if (major > 42) return
85+
if (major == 42 && minor > 7) return
86+
if (major == 42 && minor == 7 && patch >= 5) return
87+
88+
error("Using components require a version of the PostgreSQL driver higher or equal to 42.7.5")
8089
}
8190

8291
suspend fun getPersistentComponentTimeouts(): List<PersistentComponentTimeout> {
@@ -380,4 +389,4 @@ internal class ComponentRepository(
380389
}
381390

382391
private fun Instant.toSqlTimestamp(): Timestamp = Timestamp.from(this.toJavaInstant())
383-
}
392+
}

0 commit comments

Comments
 (0)