Skip to content

Instantly share code, notes, and snippets.

Created October 2, 2022 16:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext}
import slick.dbio.DBIO
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
abstract class SlickMigration extends BaseJavaMigration {
implicit val executionContext: ExecutionContext =
def action: DBIO[Unit]
override def migrate(context: Context): Unit = {
val db = new UnmanagedDatabase(context.getConnection)
Await.result(, Duration.Inf)
import java.sql.Connection
import slick.jdbc.JdbcBackend.{BaseSession, DatabaseDef}
import slick.jdbc.{JdbcBackend, JdbcDataSource}
import slick.util.AsyncExecutor
class UnmanagedJdbcDataSource(conn: Connection) extends JdbcDataSource {
override def createConnection() = conn
override def close(): Unit = ()
override val maxConnections = None
class UnmanagedSession(database: DatabaseDef) extends BaseSession(database) {
override def close(): Unit = ()
class UnmanagedDatabase(conn: Connection)
extends JdbcBackend.DatabaseDef(
new UnmanagedJdbcDataSource(conn), AsyncExecutor.default("UnmanagedDatabase-AsyncExecutor")
) {
override def createSession() = new UnmanagedSession(this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment