Skip to content

Commit

Permalink
Merge pull request #875 from playframework/mergify/bp/5.3.x/pr-859
Browse files Browse the repository at this point in the history
[5.3.x] Set unique poolName based on database name (backport #859) by @mwisnicki
  • Loading branch information
mergify[bot] authored Jun 26, 2024
2 parents 1c519d0 + 92673c5 commit 452f63a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core/src/main/scala/play/api/db/slick/SlickApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}

Expand Down

0 comments on commit 452f63a

Please sign in to comment.