-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
208 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
integrations/fly4s/src/main/scala/com/geirolz/app/toolkit/fly4s/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.geirolz.app.toolkit | ||
|
||
package object fly4s {} |
56 changes: 56 additions & 0 deletions
56
integrations/fly4s/src/main/scala/com/geirolz/app/toolkit/fly4s/syntax.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.geirolz.app.toolkit.fly4s | ||
|
||
import cats.effect.Resource | ||
import cats.effect.kernel.Async | ||
import com.geirolz.app.toolkit.{App, SimpleAppInfo} | ||
import fly4s.core.Fly4s | ||
import fly4s.core.data.Fly4sConfig | ||
|
||
object syntax extends AllSyntax | ||
private[fly4s] sealed trait AllSyntax { | ||
|
||
import cats.syntax.all.* | ||
|
||
implicit class AppResourcesLoaderOps[F[+_]: Async, FAILURE, APP_INFO <: SimpleAppInfo[?], LOGGER_T[_[_]], CONFIG, RESOURCES, DEPENDENCIES]( | ||
app: App[F, FAILURE, APP_INFO, LOGGER_T, CONFIG, RESOURCES, DEPENDENCIES] | ||
) { | ||
|
||
def beforeProvidingMigrateDatabaseWithConfig( | ||
url: CONFIG => String, | ||
user: CONFIG => Option[String] = _ => None, | ||
password: CONFIG => Option[Array[Char]] = _ => None, | ||
config: Fly4sConfig = Fly4sConfig.default, | ||
classLoader: ClassLoader = Thread.currentThread.getContextClassLoader | ||
): App[F, FAILURE, APP_INFO, LOGGER_T, CONFIG, RESOURCES, DEPENDENCIES] = | ||
beforeProvidingMigrateDatabaseWith( | ||
url = d => url(d.config), | ||
user = d => user(d.config), | ||
password = d => password(d.config), | ||
config = config, | ||
classLoader = classLoader | ||
) | ||
|
||
def beforeProvidingMigrateDatabaseWith( | ||
url: App.Dependencies[APP_INFO, LOGGER_T[F], CONFIG, DEPENDENCIES, RESOURCES] => String, | ||
user: App.Dependencies[APP_INFO, LOGGER_T[F], CONFIG, DEPENDENCIES, RESOURCES] => Option[String] = _ => None, | ||
password: App.Dependencies[APP_INFO, LOGGER_T[F], CONFIG, DEPENDENCIES, RESOURCES] => Option[Array[Char]] = _ => None, | ||
config: Fly4sConfig = Fly4sConfig.default, | ||
classLoader: ClassLoader = Thread.currentThread.getContextClassLoader | ||
): App[F, FAILURE, APP_INFO, LOGGER_T, CONFIG, RESOURCES, DEPENDENCIES] = | ||
beforeProvidingMigrateDatabase(dep => | ||
Fly4s | ||
.make[F]( | ||
url = url(dep), | ||
user = user(dep), | ||
password = password(dep), | ||
config = config, | ||
classLoader = classLoader | ||
) | ||
) | ||
|
||
def beforeProvidingMigrateDatabase( | ||
f: App.Dependencies[APP_INFO, LOGGER_T[F], CONFIG, DEPENDENCIES, RESOURCES] => Resource[F, Fly4s[F]] | ||
): App[F, FAILURE, APP_INFO, LOGGER_T, CONFIG, RESOURCES, DEPENDENCIES] = | ||
app.beforeProviding(dep => f(dep).use(_.migrate).void) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
integrations/fly4s/src/test/scala/com/geirolz/app/toolkit/fly4s/Fly4sSupportSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.geirolz.app.toolkit.fly4s | ||
|
||
import cats.effect.IO | ||
import com.geirolz.app.toolkit.fly4s.syntax.* | ||
import com.geirolz.app.toolkit.fly4s.testing.TestConfig | ||
import com.geirolz.app.toolkit.{App, SimpleAppInfo} | ||
|
||
class Fly4sSupportSuite extends munit.CatsEffectSuite { | ||
|
||
test("Syntax works as expected") { | ||
assertIO_( | ||
App[IO] | ||
.withInfo( | ||
SimpleAppInfo.string( | ||
name = "toolkit", | ||
version = "0.0.1", | ||
scalaVersion = "2.13.10", | ||
sbtVersion = "1.8.0" | ||
) | ||
) | ||
.withConfig( | ||
TestConfig( | ||
dbUrl = "jdbc:postgresql://localhost:5432/toolkit", | ||
dbUser = Some("postgres"), | ||
dbPassword = Some("postgres".toCharArray) | ||
) | ||
) | ||
.withoutDependencies | ||
.provideOne(_ => IO.unit) | ||
.beforeProvidingMigrateDatabaseWithConfig( | ||
url = _.dbUrl, | ||
user = _.dbUser, | ||
password = _.dbPassword | ||
) | ||
.run_ | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
integrations/fly4s/src/test/scala/com/geirolz/app/toolkit/fly4s/testing/TestConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.geirolz.app.toolkit.fly4s.testing | ||
|
||
import cats.Show | ||
|
||
case class TestConfig(dbUrl: String, dbUser: Option[String], dbPassword: Option[Array[Char]]) | ||
object TestConfig { | ||
implicit val show: Show[TestConfig] = Show.fromToString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters