diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2017-12-01 09:54:20 -0800 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2017-12-13 00:26:13 -0800 |
commit | fc1f5ccaa94aba0c0ecc0b4e9af885dfea320df1 (patch) | |
tree | 0acac5b59ba61c8fcf89c70281ab967972a6debb | |
parent | 7b123473ee304cc49f2763d7893618468c29cbec (diff) | |
download | slick-codegen-plugin-fc1f5ccaa94aba0c0ecc0b4e9af885dfea320df1.tar.gz slick-codegen-plugin-fc1f5ccaa94aba0c0ecc0b4e9af885dfea320df1.tar.bz2 slick-codegen-plugin-fc1f5ccaa94aba0c0ecc0b4e9af885dfea320df1.zip |
make generated SchemaDescription include statement for creating SchemaName
-rw-r--r-- | src/main/scala/Generators.scala | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/main/scala/Generators.scala b/src/main/scala/Generators.scala index 5bc192f..e02cbd6 100644 --- a/src/main/scala/Generators.scala +++ b/src/main/scala/Generators.scala @@ -65,19 +65,23 @@ class TableSourceCodeGenerator(schemaOnlyModel: m.Model, // TODO: fix upstream val tableCode = super.code.lines.drop(1).mkString("\n") - val tripleQuote = "\"\"\"" - val namespaceDDL = - s"""|val createNamespaceSchema = { - | implicit val GRUnit = slick.jdbc.GetResult(_ => ()) - | sql${tripleQuote}CREATE SCHEMA IF NOT EXISTS "$schemaName";${tripleQuote}.as[Unit] - |} - | - |val dropNamespaceSchema = { - | implicit val GRUnit = slick.jdbc.GetResult(_ => ()) - | sql${tripleQuote}DROP SCHEMA "$schemaName" CASCADE;${tripleQuote}.as[Unit] - |} """ - - tableCode + "\n\n" + namespaceDDL + if (ddlEnabled && schemaName != "public") { // TODO: "public" is postgres-specific + // TODO: make generated DDL overrideable upstream + try { + val (before, ddl +: after) = tableCode.lines.toVector.span(! _.contains("val schema")) + val Array(identifier, tablesDDL) = ddl.split('=').map(_.trim) + val schemaDDL: Vector[String] = + s"""|lazy val schema: profile.SchemaDescription = { + | val schemaDDL = profile.DDL( + | create1 = "create schema " + profile.quoteIdentifier("$schemaName"), + | drop2 = "drop schema " + profile.quoteIdentifier("$schemaName")) + | schemaDDL ++ ${tablesDDL.trim} + |}""".stripMargin.lines.toVector + (before ++ schemaDDL ++ after).mkString("\n") + } catch { + case _: MatchError => throw new Exception("failed to modify schemaddl line") + } + } else tableCode } override def Table = new this.TypedIdTable(_) { table => |