2017-12-21 8 views
1

Ich habe Evolution Problem Unbekannten Datentyp: "JSONB" wenn Ausführen von Tests in playframework mitUnbekannter Datentyp "JSONB", wenn Tests im Spiel glatt mit H2 Database läuft

  • playframework V2.6.6 für scala
  • Play-Slick v3.0.2
  • Play-Slick-Evolutionen v3.0.2
  • postgresql - 42.0.0
  • h2database - 1.4.194

Mein H2DbConnector sieht wie folgt aus:

import entities.StubData._ 
import org.scalatest.{BeforeAndAfterAll, FunSuite} 
import play.api.db.DBApi 
import play.api.db.evolutions.Evolutions 
import play.api.inject.guice.GuiceApplicationBuilder 

trait H2DbConnector extends FunSuite with BeforeAndAfterAll { 
    val appBuilder = new GuiceApplicationBuilder() 
    .configure(configuration) 

    val injector = appBuilder.injector 
    lazy val databaseApi = injector.instanceOf[DBApi] 

    override def beforeAll() = { 
    Evolutions.applyEvolutions(databaseApi.database("default")) 
    } 

    override def afterAll() = { 
    Evolutions.cleanupEvolutions(databaseApi.database("default")) 
    } 
} 

In application.test.conf

slick.dbs.default.driver = "slick.driver.H2Driver$" 
slick.dbs.default.db.driver = "org.h2.Driver" 
slick.dbs.default.db.url = "jdbc:h2:mem:play;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=FALSE" 

ich eine problematische Linie in Evolutionen haben 2.sql Datei

ALTER TABLE "Messages" ADD COLUMN "metaJson" JSONB NULL; 

Wenn ich Dao Tests laufen Fehler wie

2017-12-21 16:08:40,409 [error] p.a.d.e.DefaultEvolutionsApi - Unknown data type: "JSONB"; SQL statement: 
ALTER TABLE "Messages" ADD COLUMN "metaJson" JSONB NULL [50004-194] [ERROR:50004, SQLSTATE:HY004] 
[info] OptoutsDaoTest *** ABORTED *** 
[info] play.api.db.evolutions.InconsistentDatabase: Database 'default' is in an inconsistent state![An evolution has not been applied properly. Please check the problem and resolve it manually before marking it as resolved.] 
[info] at play.api.db.evolutions.DatabaseEvolutions.$anonfun$checkEvolutionsState$3(EvolutionsApi.scala:285) 
[info] at play.api.db.evolutions.DatabaseEvolutions.$anonfun$checkEvolutionsState$3$adapted(EvolutionsApi.scala:270) 
[info] at play.api.db.evolutions.DatabaseEvolutions.executeQuery(EvolutionsApi.scala:317) 
[info] at play.api.db.evolutions.DatabaseEvolutions.checkEvolutionsState(EvolutionsApi.scala:270) 
[info] at play.api.db.evolutions.DatabaseEvolutions.evolve(EvolutionsApi.scala:239) 
[info] at play.api.db.evolutions.Evolutions$.applyEvolutions(Evolutions.scala:193) 
[info] at H2DbConnector.beforeAll(H2DbConnector.scala:15) 
[info] at H2DbConnector.beforeAll$(H2DbConnector.scala:14) 
[info] at OptoutsDaoTest.beforeAll(OptoutsDaoTest.scala:5) 
[info] at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:212) 
[info] ... 

Können Sie mir bitte helfen, dieses Problem zu beheben?

+0

Sie können sich [Acolyte] (http://acolyte.eu.org/) ansehen, um eine beliebige JDBC-Verbindung zu "mocken", egal, welche Ziel-DB zur Laufzeit vorliegt. – cchantep

Antwort

1

H2 unterstützt keinen JSONB Spaltentyp.

Alle unterstützten Spaltentypen Supported datatypes of H2

Try Postgres auch in Tests verwenden oder Standard-SQL-Statements schreiben, die beide Datenbanken verstehen.

+0

Gibt es eine weitere Problemumgehung zur Unterstützung des Datentyps ** JSON ** in Postgres und H2-Datenbank? – Azik

+0

Erstelle einen Testaccount für Postgres und verwende Postgres auch in deinen Tests. – pamu

+0

vielen dank für ihre hilfe! – Azik

Verwandte Themen