mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 23:55:43 +00:00
Make Postgres history load failures explicit (#6981)
This commit is contained in:
@@ -380,6 +380,10 @@ jobs:
|
||||
validate_env "EAGLE_IMAGE" "${EAGLE_IMAGE}" "" || VALIDATION_FAILED=1
|
||||
validate_env "JWT_PRIVATE_KEY" "${JWT_PRIVATE_KEY}" "" || VALIDATION_FAILED=1
|
||||
validate_env "DO_REGISTRY_TOKEN" "${DO_REGISTRY_TOKEN}" "" || VALIDATION_FAILED=1
|
||||
validate_env "EAGLE_POSTGRES_HOST" "${EAGLE_POSTGRES_HOST}" "" || VALIDATION_FAILED=1
|
||||
validate_env "EAGLE_POSTGRES_DATABASE" "${EAGLE_POSTGRES_DATABASE}" "" || VALIDATION_FAILED=1
|
||||
validate_env "EAGLE_POSTGRES_USER" "${EAGLE_POSTGRES_USER}" "" || VALIDATION_FAILED=1
|
||||
validate_env "EAGLE_POSTGRES_PASSWORD" "${EAGLE_POSTGRES_PASSWORD}" "" || VALIDATION_FAILED=1
|
||||
|
||||
if [ "\${VALIDATION_FAILED}" -eq 1 ]; then
|
||||
echo ""
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.eagle0.eagle.service
|
||||
import java.io.File
|
||||
|
||||
import net.eagle0.eagle.library.actions.applier.ActionResultWithResultingState
|
||||
import net.eagle0.eagle.library.EagleInternalException
|
||||
import net.eagle0.eagle.model.action_result.ActionResultT
|
||||
import net.eagle0.eagle.model.state.game_state.GameState
|
||||
import net.eagle0.eagle.service.persistence.{Persister, SaveDirectory}
|
||||
@@ -50,8 +51,20 @@ private[service] object GameHistoryFactory {
|
||||
else None
|
||||
}
|
||||
|
||||
if HistoryBackendConfig.usePostgres then PostgresHistory.loaded(gameId).orElse(sqlite)
|
||||
else sqlite
|
||||
if HistoryBackendConfig.usePostgres then {
|
||||
PostgresHistory.requireConfigured()
|
||||
val postgres = PostgresHistory.loaded(gameId)
|
||||
if postgres.isEmpty then
|
||||
println(
|
||||
s"GameHistoryFactory: no Postgres history found for game ${gameId.toHexString}; trying SQLite fallback"
|
||||
)
|
||||
val fallback = postgres.orElse(sqlite)
|
||||
if fallback.isEmpty then
|
||||
throw new EagleInternalException(
|
||||
s"No history found for game ${gameId.toHexString}: Postgres schema missing and SQLite game.db missing"
|
||||
)
|
||||
fallback
|
||||
} else sqlite
|
||||
}
|
||||
|
||||
private def sqliteDbFile(gameId: GameId): File =
|
||||
|
||||
@@ -614,6 +614,9 @@ object PostgresHistory {
|
||||
try {
|
||||
val schemaName = schemaNameForGame(gameId)
|
||||
if !schemaExists(connection, schemaName) then {
|
||||
println(
|
||||
s"PostgresHistory: no schema $schemaName for game ${gameId.toHexString}"
|
||||
)
|
||||
connection.close()
|
||||
None
|
||||
} else {
|
||||
@@ -628,6 +631,13 @@ object PostgresHistory {
|
||||
}
|
||||
}.getOrElse(None)
|
||||
|
||||
def requireConfigured(): Unit =
|
||||
if config.isEmpty then
|
||||
throw new EagleInternalException(
|
||||
"HistoryBackend=postgres requires EAGLE_POSTGRES_HOST, EAGLE_POSTGRES_DATABASE, " +
|
||||
"EAGLE_POSTGRES_USER, and EAGLE_POSTGRES_PASSWORD"
|
||||
)
|
||||
|
||||
private def config: Option[PostgresConfig] =
|
||||
for
|
||||
host <- envNonEmpty("EAGLE_POSTGRES_HOST")
|
||||
|
||||
Reference in New Issue
Block a user