From 92673c5fa6f747cb37115cd1e58a1d457a0f8815 Mon Sep 17 00:00:00 2001 From: Marcin Wisnicki Date: Tue, 14 May 2024 18:01:00 -0400 Subject: [PATCH] Set unique poolName based on database name (cherry picked from commit 83efdb4d54e11c20f0d5117e1dddaceb41e1d83d) --- .../src/main/scala/play/api/db/slick/SlickApi.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/src/main/scala/play/api/db/slick/SlickApi.scala b/src/core/src/main/scala/play/api/db/slick/SlickApi.scala index eb842dd9..fecfea1f 100644 --- a/src/core/src/main/scala/play/api/db/slick/SlickApi.scala +++ b/src/core/src/main/scala/play/api/db/slick/SlickApi.scala @@ -8,8 +8,10 @@ import scala.util.Success import scala.util.Try import scala.util.control.NonFatal import com.typesafe.config.Config -import javax.inject.Inject +import com.typesafe.config.ConfigValue +import com.typesafe.config.ConfigValueFactory +import javax.inject.Inject import play.api.Configuration import play.api.Environment import play.api.Logger @@ -94,11 +96,15 @@ object DefaultSlickApi { @throws(classOf[PlayException]) private def create(): DatabaseConfig[BasicProfile] = { - try DatabaseConfig.forConfig[BasicProfile](path = "", config = config) + val config2 = + if (config.hasPath("db.poolName")) config + else + config.withValue("db.poolName", ConfigValueFactory.fromAnyRef(s"$name.db")) + try DatabaseConfig.forConfig[BasicProfile](path = "", config = config2) catch { case NonFatal(t) => logger.error(s"Failed to create Slick database config for key $name.", t) - throw Configuration(config).reportError(name, s"Cannot connect to database [$name]", Some(t)) + throw Configuration(config2).reportError(name, s"Cannot connect to database [$name]", Some(t)) } }