title: Slick 3.0 Custom Code Generation for Oracle
body: <p>I am trying to generate Slick 3.0 code for Oracle. The DB user points to two schemas that have tables with the same name so the generated code has duplicate classes. I would like to filter out the tables from the schema that end in "STAGE"</p>
  
  <p>Here is the code:</p>
  
  <pre><code>object CodeGen2 extends App {
    //https://stackoverflow.com/questions/28285129/slick-code-generation-for-only-a-single-schema
  
    val slickDriver = "com.typesafe.slick.driver.oracle.OracleDriver"
    val jdbcDriver = "oracle.jdbc.OracleDriver"
    val url = "jdbc:oracle:thin:@dbhost:1521:dbsid"
    val user = "dbuser"
    val password = "dbpassword"
    val destDir = "src/main/scala"
    val destPackage = "com.mycompany.mypackage"
  
    import scala.concurrent.{ExecutionContext, Await, Future}
    import scala.concurrent.duration.Duration
    import slick.codegen.SourceCodeGenerator
    import scala.concurrent.ExecutionContext.Implicits.global
    import slick.jdbc.JdbcModelBuilder
    import slick.jdbc.meta.MTable
    import com.typesafe.slick.driver.oracle.OracleDriver
    import slick.jdbc.JdbcBackend.DatabaseFactoryDef
  
  
    println("Starting codegen...")
    val db = OracleDriver.simple.Database.forURL(url, user=user, password=password, driver=jdbcDriver)
    val filteredTables = OracleDriver.defaultTables.filter(
          (t: MTable) =&gt; !t.name.schema.get.endsWith("STAGE")
        )
  
    val modelAction = OracleDriver.createModel(filteredTables, true)
    println("Generating model...")
    val model = Await.result(db.run(modelAction), Duration.Inf)
    val codegen = new SourceCodeGenerator(model) {
      // for illustration
      val noStage = model.tables.filter { table =&gt; !table.name.schema.get.endsWith("STAGE") } 
      noStage.foreach { table =&gt; println(table.name.schema.get) }
  
    }
    println("Generating files...")
    codegen.writeToFile(
      slickDriver, destDir, destPackage, "Tables", "Tables.scala"
    )
  //  slick.codegen.SourceCodeGenerator.main(
  //    Array(slickDriver, jdbcDriver, url, destDir, destPackage, user, password)
  //  )
    println("Finished codegen.")
  }
  </code></pre>
  
  <p>I try and filter the defaultTables but the signature is Seq[MTable] => Boolean so I have no idea how to deal with that. Is filtering the tables passed to driver.createModel the correct approach? I looked and tried other code with override(n) methods but nothing seemed workable. </p>
  
  <pre><code>name := "slick-test"
  version := "1.0"
  scalaVersion := "2.11.6"
  
  libraryDependencies ++= Seq(
    "com.typesafe.slick" %% "slick" % "3.0.0",
    "org.slf4j" % "slf4j-nop" % "1.6.4",
    "com.typesafe.slick" %% "slick-extensions" % "3.0.0",
    "com.typesafe.slick" %% "slick-codegen" % "3.0.0"
  )
  
  resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/maven-releases/"
  </code></pre>
  
  <p>Thanks.</p>