Permalink
Browse files

MySQL modelbuilder schema name (#1528)

1 parent 01d3c89 commit 51e14f2756ed29b8c92a24b0ae24f2acd0b85c6f @trevorsibanda trevorsibanda committed with cvogt Sep 2, 2016
@@ -1 +1,3 @@
-CREATE TABLE LongTextTest( entry1 LONGTEXT NOT NULL , entry2 MEDIUMTEXT NOT NULL , entry3 TEXT NOT NULL , entry4 VARCHAR(255) NOT NULL );
+CREATE TABLE `LongTextTest`( entry1 LONGTEXT NOT NULL , entry2 MEDIUMTEXT NOT NULL , entry3 TEXT NOT NULL , entry4 VARCHAR(255) NOT NULL );
+
+CREATE TABLE `table_name`( id INT NOT NULL );
@@ -127,6 +127,34 @@ val SimpleA = CustomTyping.SimpleA
""".stripMargin
},
new UUIDConfig("Postgres2", StandardTestDBs.Postgres, "Postgres", Seq("/dbs/uuid-postgres.sql")),
+ new Config("MySQL", StandardTestDBs.MySQL, "MySQL", Seq("/dbs/mysql.sql") ){
+ override def generator: DBIO[SourceCodeGenerator] =
+ tdb.profile.createModel(ignoreInvalidDefaults=false).map(new SourceCodeGenerator(_){
+ override def parentType = Some("com.typesafe.slick.testkit.util.TestCodeRunner.TestCase")
+ override def code = {
+ val testcode =
+ """
+ | val createStmt = schema.create.statements.mkString
+ | assertTrue(createStmt contains "`entry1` LONGTEXT ")
+ | assertTrue(createStmt contains "`entry2` MEDIUMTEXT")
+ | assertTrue(createStmt contains "`entry3` TEXT" )
+ | assertTrue(createStmt contains "`entry4` VARCHAR(255)")
+ | DBIO.seq( schema.create ,
+ | TableName += TableNameRow(0),
+ | TableName.result.map{ case Seq(TableNameRow(id) ) => assertTrue("Schema name should be `slick_test`" , TableName.baseTableRow.schemaName.get eq "slick_test" ) }
+ | )
+ """.stripMargin
+ s"""
+ |lazy val tdb = $fullTdbName
+ |def test = {
+ | import org.junit.Assert._
+ | import scala.concurrent.ExecutionContext.Implicits.global
+ | $testcode
+ |}
+ """.stripMargin + super.code
+ }
+ })
+ },
new Config("EmptyDB", StandardTestDBs.H2Mem, "H2Mem", Nil),
new Config("Oracle1", StandardTestDBs.Oracle, "Oracle", Seq("/dbs/oracle1.sql")) {
override def useSingleLineStatements = true
@@ -95,6 +95,12 @@ trait MySQLProfile extends JdbcProfile { profile =>
else l
}
}
+
+ //Reference: https://github.com/slick/slick/issues/1419
+ override def createTableNamer(meta: MTable): TableNamer = new TableNamer(meta){
+ override def schema = meta.name.catalog
+ override def catalog = meta.name.schema
+ }
}
override def createModelBuilder(tables: Seq[MTable], ignoreInvalidDefaults: Boolean)(implicit ec: ExecutionContext): JdbcModelBuilder =

0 comments on commit 51e14f2

Please sign in to comment.