Skip to content

Commit

Permalink
Set unique poolName based on database name
Browse files Browse the repository at this point in the history
  • Loading branch information
mwisnicki committed May 14, 2024
1 parent 087834b commit d44d2fc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/core/src/main/scala/play/api/db/slick/SlickApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import scala.util.Failure
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.{Config, ConfigValue, ConfigValueFactory}

import javax.inject.Inject
import play.api.Configuration
import play.api.Environment
import play.api.Logger
Expand Down Expand Up @@ -94,11 +94,13 @@ 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 d44d2fc

Please sign in to comment.