Last active
July 1, 2020 20:47
-
-
Save bhameyie/89fa2d872e6a92e9b8060155f7e39850 to your computer and use it in GitHub Desktop.
Only generate tables for a single schema
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
import slick.codegen.SourceCodeGenerator | |
import slick.jdbc.JdbcProfile | |
import slick.model.Model | |
import scala.concurrent.{Await, ExecutionContext} | |
import scala.concurrent.duration.Duration | |
object SourceCodeGenerator { | |
def run(slickDriver: String, | |
jdbcDriver: String, | |
url: String, | |
outputDir: String, | |
pkg: String, | |
schema:String): Unit = { | |
val driver: JdbcProfile = | |
Class.forName(slickDriver + "$").getField("MODULE$").get(null).asInstanceOf[JdbcProfile] | |
val dbFactory = driver.api.Database | |
val db = dbFactory.forURL(url, driver = jdbcDriver, keepAliveConnection = true) | |
try { | |
val allSchemas = Await.result(db.run( | |
driver.createModel(None, ignoreInvalidDefaults = false)(ExecutionContext.global).withPinnedSession), Duration.Inf) | |
val publicSchema = new Model(allSchemas.tables.filter(x=> x.name.schema.contains(schema)), allSchemas.options) | |
new SourceCodeGenerator(publicSchema).writeToFile(slickDriver, outputDir, pkg) | |
} finally db.close | |
} | |
def main(args: Array[String]) = { | |
//Handle parameter reading then call run | |
??? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment