diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2017-12-13 03:27:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-13 03:27:56 -0500 |
commit | 0ef6befb187e2302209793fa9a9c207cea0118d3 (patch) | |
tree | 88cb43afd79c7c26b88682ebe18a3d2c3714e60d | |
parent | 6ed99e4ec50fa2273b140bf26833593224b4c1a4 (diff) | |
parent | fc1f5ccaa94aba0c0ecc0b4e9af885dfea320df1 (diff) | |
download | slick-codegen-plugin-0ef6befb187e2302209793fa9a9c207cea0118d3.tar.gz slick-codegen-plugin-0ef6befb187e2302209793fa9a9c207cea0118d3.tar.bz2 slick-codegen-plugin-0ef6befb187e2302209793fa9a9c207cea0118d3.zip |
Merge pull request #33 from drivergroup/ddl-schema-name
add namespaceSchema generation to SchemaDescription
-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 => |