diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2017-02-16 15:27:46 -0500 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2017-02-16 16:17:47 -0500 |
commit | 6756e87908dfff5ec46c0b5eb78dc7cb69132457 (patch) | |
tree | fa7ff1a973a867c1644e59cf2ad59e733621e613 /src/main/scala | |
parent | 1ec9678729ca29d93f9eaebe25b473f8f4a0f969 (diff) | |
download | slick-codegen-plugin-6756e87908dfff5ec46c0b5eb78dc7cb69132457.tar.gz slick-codegen-plugin-6756e87908dfff5ec46c0b5eb78dc7cb69132457.tar.bz2 slick-codegen-plugin-6756e87908dfff5ec46c0b5eb78dc7cb69132457.zip |
throw exception for missing tables
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/NamespacedCodegen.scala | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/main/scala/NamespacedCodegen.scala b/src/main/scala/NamespacedCodegen.scala index 21876ea..db6e805 100644 --- a/src/main/scala/NamespacedCodegen.scala +++ b/src/main/scala/NamespacedCodegen.scala @@ -252,18 +252,26 @@ object SchemaParser { def createModel( jdbcProfile: JdbcProfile, mappedSchemasOpt: Option[Map[String, List[String]]]): DBIO[Model] = { - val allTables: DBIO[Vector[MTable]] = MTable.getTables - - val filteredTables = mappedSchemasOpt.map( - mappedSchemas => - allTables.map( - (tables: Vector[MTable]) => - tables.filter( - table => - table.name.schema - .flatMap(mappedSchemas.get) - .exists(ts => ts.isEmpty || ts.contains(table.name.name))))) - - jdbcProfile.createModel(filteredTables orElse Some(allTables)) + import slick.jdbc.meta.MQName + + val filteredTables = mappedSchemasOpt.map { mappedSchemas => + MTable.getTables.map { (tables: Vector[MTable]) => + mappedSchemas.flatMap { + case (schemaName, tableNames) => + tableNames.map( + tableName => + tables + .find(table => + table.name match { + case MQName(_, Some(`schemaName`), `tableName`) => true + case _ => false + }) + .getOrElse(throw new IllegalArgumentException( + s"$schemaName.$tableName does not exist in the connected database."))) + }.toList + } + } + + jdbcProfile.createModel(filteredTables) } } |