Permalink
Browse files

Improve mysql string type inference

1 parent 8dcb5e3 commit 248bf1882adcce73cdeed7ac75295d50aac851e1 @trevorsibanda trevorsibanda committed Aug 8, 2016
@@ -0,0 +1 @@
+CREATE TABLE LongTextTest( entry1 LONGTEXT NOT NULL , entry2 MEDIUMTEXT NOT NULL , entry3 TEXT NOT NULL , entry4 VARCHAR(255) NOT NULL );
@@ -103,6 +103,17 @@ val SimpleA = CustomTyping.SimpleA
| ).transactionally
""".stripMargin
},
+ new Config("MySQL", StandardTestDBs.MySQL, "MySQL", Seq("/dbs/mysql.sql")){
+ override def 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 )
+ """.stripMargin
+ },
new UUIDConfig("Postgres2", StandardTestDBs.Postgres, "Postgres", Seq("/dbs/uuid-postgres.sql")),
new Config("EmptyDB", StandardTestDBs.H2Mem, "H2Mem", Nil),
new Config("Oracle1", StandardTestDBs.Oracle, "Oracle", Seq("/dbs/oracle1.sql")) {
@@ -113,7 +113,12 @@ trait MySQLProfile extends JdbcProfile { profile =>
override def defaultSqlTypeName(tmd: JdbcType[_], sym: Option[FieldSymbol]): String = tmd.sqlType match {
case java.sql.Types.VARCHAR =>
sym.flatMap(_.findColumnOption[RelationalProfile.ColumnOption.Length]) match {
- case Some(l) => if(l.varying) s"VARCHAR(${l.length})" else s"CHAR(${l.length})"
+ case Some(l) => if(l.varying){
+ //http://dev.mysql.com/doc/refman/5.7/en/string-type-overview.html
+ if(l.length <= 65535 ) s"VARCHAR(${l.length})"
+ else if(l.length <= 16777215 ) "MEDIUMTEXT"
+ else "LONGTEXT"
+ } else s"CHAR(${l.length})"
case None => defaultStringType match {
case Some(s) => s
case None =>

0 comments on commit 248bf18

Please sign in to comment.