1
votes

In my tests, I'm trying to setup a test database based on the schema defined in slick, which in turn is generated with the slick code generator based on an existing database. To do so, I'm extending WithApplication and redefining the around method like so:

abstract class WithDbData extends WithApplication {
 def ds = DB.getDataSource("test")
  def slickDb = Database.forDataSource(ds)
  override def around[T: AsResult](t: => T): Result = super.around {
    setup
    val result = AsResult.effectively(t)
    teardown
    result
  }

  def setup = {
    slickDb.withSession { implicit session =>
      ddl.create
    }
  }

  def teardown = {
    slickDb.withSession { implicit session =>
      ddl.drop
    }
  }
}

But when I run the tests, I'm getting a

MySqlSyntaxErrorException : Column length too big for column 'text' (max = 21845); use BLOB or TEXT instead  (null:-2).

I'm using MySql for development and for testing, and part of the schema generated by the code generator is like so:

/** Database column text DBType(TEXT), Length(65535,true) */
val text: Column[String] = column[String]("text", O.Length(65535,varying=true))

It seems that the ddl generator is trying to create the text column as a varchar or something like that, instead of as text, as it was originally intended, because in the original database that column is of type text.

In the autogenerated slick data model I have as profile = scala.slick.driver.MySQLDriver, I've also imported scala.slick.driver.MySQLDriver.simple._ in my test class so I shouldn't have any problem because of mixing drivers.

I'm using play 2.3, slick 2.1.0, codegen 2.1.0 and play-slick 0.8.0.

I'd appreciate any light on this matter.

2

2 Answers

1
votes

It's a bug in the code generator. github.com/slick/slick/issues/975

You can work around it by customizing the code generator. See http://slick.typesafe.com/doc/2.1.0/code-generation.html

One easy way to do it is override def dbType = true . You loose cross-vendor portability but get the exact types. You may have to filter Length out of def options, not sure.

Also discussed here: https://github.com/slick/slick/issues/982

0
votes

You may change the column manually:

Create the table as standar varchar(255):

val text: Column[String] = column[String]("text", O.Length(255,varying=true))

After that you can change the database:

alter table your_table change `text` `text` text;

And restore the values:

val text: Column[String] = column[String]("text", O.Length(65535,varying=true))

In the other hand: you can add a custom field definition:

def recipe = column[Option[String]]("text_column", O.DBType("TEXT"))

Note: I changed the column name to text_column because text is a reserved word in MySQL.