diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2016-09-09 18:40:05 -0400 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2016-09-09 18:40:05 -0400 |
commit | ee0f1822447ec1ff84ecad2e2b9a19ce7dc37d36 (patch) | |
tree | 29d64bf2518e0365e9ba9e7c599038c4a84631f5 /src/main/scala | |
parent | f932919f6bc57f5d080dd42e17af83af0a6ea080 (diff) | |
download | slick-codegen-plugin-ee0f1822447ec1ff84ecad2e2b9a19ce7dc37d36.tar.gz slick-codegen-plugin-ee0f1822447ec1ff84ecad2e2b9a19ce7dc37d36.tar.bz2 slick-codegen-plugin-ee0f1822447ec1ff84ecad2e2b9a19ce7dc37d36.zip |
make manualForeignKeys a plugin parameter
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/CodegenPlugin.scala | 15 | ||||
-rw-r--r-- | src/main/scala/NamespacedCodegen.scala | 19 |
2 files changed, 13 insertions, 21 deletions
diff --git a/src/main/scala/CodegenPlugin.scala b/src/main/scala/CodegenPlugin.scala index d6ac8c8..7b51fb8 100644 --- a/src/main/scala/CodegenPlugin.scala +++ b/src/main/scala/CodegenPlugin.scala @@ -4,18 +4,25 @@ import complete.DefaultParsers._ object CodegenPlugin extends AutoPlugin { override def requires = sbt.plugins.JvmPlugin + type TableColumn = (String, String) + object autoImport { lazy val genTables = TaskKey[Seq[File]]("gen-tables") - lazy val dbConfigURI = SettingKey[String]("uri for the database configuration") + lazy val uri = SettingKey[String]("uri for the database configuration") lazy val pkg = SettingKey[String]("package in which to place generated code") lazy val tablesFilename = SettingKey[String]("path for slick table models") lazy val rowsFilename = SettingKey[String]("path for row case classes") lazy val schemas = SettingKey[List[String]]("schemas and tables to process") + lazy val manualForeignKeys = SettingKey[Map[TableColumn, TableColumn]]("foreign key references to data models add manually") lazy val slickCodeGenTask = Def.task { - val uri = new java.net.URI(dbConfigURI.value) - - codegen.NamespacedCodegen.run(uri, pkg.value, tablesFilename.value, rowsFilename.value, schemas.value) + codegen.NamespacedCodegen.run( + new java.net.URI(uri.value), + pkg.value, + tablesFilename.value, + rowsFilename.value, + schemas.value, + manualForeignKeys.value) Seq(file(tablesFilename.value), file(rowsFilename.value)) } diff --git a/src/main/scala/NamespacedCodegen.scala b/src/main/scala/NamespacedCodegen.scala index b853e9a..220f4f2 100644 --- a/src/main/scala/NamespacedCodegen.scala +++ b/src/main/scala/NamespacedCodegen.scala @@ -41,22 +41,6 @@ object NamespacedCodegen { .get(t.name.schema.getOrElse("")) .fold(false)(ts => ts.isEmpty || ts.contains(t.name.name)))))) - val manualForeignKeys: Map[(String, String), (String, String)] = - Map( - ("portal.case_tumor_info", "patient_id") -> (("patients.patients", "patient_id")), - ("portal.case_tumor_info", "case_id") -> (("work_queues.reports", "case_id")), - ("portal.case_tumor_info", "cancer_id") -> (("patients.cancer", "cancer_id")), - ("confidential.join_pat", "patient_id") -> (("patients.patients", "patient_id")), - ("portal.case_tumor_info", "ordering_physician") -> (("patients.oncologists", "oncologist_id")), - ("patients.oncologists_case_permissions_view", "oncologist_id") -> (("patients.oncologists", "oncologist_id")), - ("patients.oncologists_case_permissions_view", "case_id") -> (("work_queues.reports", "case_id")), - ("case_accessioning.case_accessioning", "case_id") -> (("work_queues.reports", "case_id")), - ("case_accessioning.case_accessioning", "cancer_id") -> (("patients.cancer", "cancer_id")), - ("experiments.somatic_snvs_indels_filtered", "cancer_id") -> (("patients.cancer", "cancer_id")), - ("experiments.experiments", "case_id") -> (("work_queues.reports", "case_id")), - ("samples.samples", "case_id") -> (("work_queues.reports", "case_id")) // TODO: Several of these can be added in a PR on postgres. - ) - def references(dbModel: Model, tcMappings: Map[(String, String), (String, String)]): Map[(String, String), (Table, Column)] = { def getTableColumn(tc: (String, String)) : (Table, Column) = { val (tableName, columnName) = tc @@ -80,7 +64,8 @@ object NamespacedCodegen { pkg: String, filename: String, typesFilename: String, - schemaTableNames: List[String] + schemaTableNames: List[String], + manualForeignKeys: Map[(String, String), (String, String)] ): Unit = { val dc = DatabaseConfig.forURI[JdbcProfile](uri) val slickDriver = if(dc.driverIsObject) dc.driverName else "new " + dc.driverName |