Domanda

I use (successfully) the flyway-play plugin in dev and prod mode. I also want to use it in test mode. The documentation says, it runs migrations automatically in test mode.

I use scala test and my testcases are wrapped in a fake application with

val fakeApplication = FakeApplication(additionalConfiguration = Map(
  "db.default.driver"->"org.h2.Driver",
  "db.default.url"->"jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;",
  "db.default.user"->"",
  "db.default.password"->""
))

When running test cases, the automigration fails with "Schema public not found":

[info]   com.googlecode.flyway.core.command.FlywaySqlScriptException: Error executing     statement at line 17: CREATE TABLE "public"."schema_version" (
[info]     "version_rank" INT NOT NULL,
[info]     "installed_rank" INT NOT NULL,
[info]     "version" VARCHAR(50) NOT NULL,
[info]     "description" VARCHAR(200) NOT NULL,
[info]     "type" VARCHAR(20) NOT NULL,
[info]     "script" VARCHAR(1000) NOT NULL,
[info]     "checksum" INT,
[info]     "installed_by" VARCHAR(100) NOT NULL,
[info]     "installed_on" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
[info]     "execution_time" INT NOT NULL,
[info]     "success" BOOLEAN NOT NULL
[info] )
[info]   at com.googlecode.flyway.core.dbsupport.SqlScript.execute(SqlScript.java:92)
[info]   at     com.googlecode.flyway.core.metadatatable.MetaDataTableImpl.createIfNotExists(MetaDataTableIm    pl.java:114)
[info]   at     com.googlecode.flyway.core.metadatatable.MetaDataTableImpl.lock(MetaDataTableImpl.java:120)
[info]   at     com.googlecode.flyway.core.command.DbMigrate$1.doInTransaction(DbMigrate.java:137)
[info]   at     com.googlecode.flyway.core.command.DbMigrate$1.doInTransaction(DbMigrate.java:135)
[info]   at     com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72    )
[info]   at com.googlecode.flyway.core.command.DbMigrate.migrate(DbMigrate.java:135)
[info]   at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:872)
[info]   at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:819)
[info]   at com.googlecode.flyway.core.Flyway.execute(Flyway.java:1200)
[info]   ...
[info]   Cause: org.h2.jdbc.JdbcSQLException: Schema "public" nicht gefunden
[info] Schema "public" not found; SQL statement:
[info] CREATE TABLE "public"."schema_version" (
[info]     "version_rank" INT NOT NULL,
[info]     "installed_rank" INT NOT NULL,
[info]     "version" VARCHAR(50) NOT NULL,
[info]     "description" VARCHAR(200) NOT NULL,
[info]     "type" VARCHAR(20) NOT NULL,
[info]     "script" VARCHAR(1000) NOT NULL,
[info]     "checksum" INT,
[info]     "installed_by" VARCHAR(100) NOT NULL,
[info]     "installed_on" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
[info]     "execution_time" INT NOT NULL,
[info]     "success" BOOLEAN NOT NULL
[info] ) [90079-172]
[info]   at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
[info]   at org.h2.message.DbException.get(DbException.java:169)
[info]   at org.h2.message.DbException.get(DbException.java:146)
[info]   at org.h2.command.Parser.getSchema(Parser.java:613)
[info]   at org.h2.command.Parser.getSchema(Parser.java:620)
[info]   at org.h2.command.Parser.parseCreateTable(Parser.java:5254)
[info]   at org.h2.command.Parser.parseCreate(Parser.java:3841)
[info]   at org.h2.command.Parser.parsePrepared(Parser.java:324)
[info]   at org.h2.command.Parser.parse(Parser.java:279)
[info]   at org.h2.command.Parser.parse(Parser.java:251)

What exactly does this error mean? Why is it using the public schema? My database config defines "db.default", not "db.public". What is the public schema? I didn't define it anywhere.

Any ideas on how I can make the test cases run (or at least get a step further)?

edit:

I found the hint ( Schema related problems with Flyway / Spring and H2 embedded database ) not to use MODE=MySQL in the h2 db url. Unfortunatelly I seem to need it for slick. If I don't use it, I get

[info]   com.googlecode.flyway.core.command.FlywaySqlScriptException: Error executing statement at line 10: SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"
[info]   at com.googlecode.flyway.core.dbsupport.SqlScript.execute(SqlScript.java:92)
[info]   at com.googlecode.flyway.core.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:72)
[info]   at com.googlecode.flyway.core.command.DbMigrate$2.doInTransaction(DbMigrate.java:243)
[info]   at com.googlecode.flyway.core.command.DbMigrate$2.doInTransaction(DbMigrate.java:241)
[info]   at com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
[info]   at com.googlecode.flyway.core.command.DbMigrate.applyMigration(DbMigrate.java:241)
[info]   at com.googlecode.flyway.core.command.DbMigrate.access$700(DbMigrate.java:44)
[info]   at com.googlecode.flyway.core.command.DbMigrate$1.doInTransaction(DbMigrate.java:186)
[info]   at com.googlecode.flyway.core.command.DbMigrate$1.doInTransaction(DbMigrate.java:135)
[info]   at com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
[info]   ...
[info]   Cause: org.h2.jdbc.JdbcSQLException: Syntax Fehler in SQL Befehl "SET SQL_MODE[*] = ""NO_AUTO_VALUE_ON_ZERO"""; erwartet "@, AUTOCOMMIT, MVCC, EXCLUSIVE, IGNORECASE, PASSWORD, SALT, MODE, COMPRESS_LOB, DATABASE, COLLATION, BINARY_COLLATION, CLUSTER, DATABASE_EVENT_LISTENER, ALLOW_LITERALS, DEFAULT_TABLE_TYPE, CREATE, HSQLDB.DEFAULT_TABLE_TYPE, PAGE_STORE, CACHE_TYPE, FILE_LOCK, DB_CLOSE_ON_EXIT, AUTO_SERVER, AUTO_SERVER_PORT, AUTO_RECONNECT, ASSERT, ACCESS_MODE_DATA, OPEN_NEW, JMX, PAGE_SIZE, RECOVER, NAMES, SCHEMA, DATESTYLE, SEARCH_PATH, SCHEMA_SEARCH_PATH, LOGSIZE"
[info] Syntax error in SQL statement "SET SQL_MODE[*] = ""NO_AUTO_VALUE_ON_ZERO"""; expected "@, AUTOCOMMIT, MVCC, EXCLUSIVE, IGNORECASE, PASSWORD, SALT, MODE, COMPRESS_LOB, DATABASE, COLLATION, BINARY_COLLATION, CLUSTER, DATABASE_EVENT_LISTENER, ALLOW_LITERALS, DEFAULT_TABLE_TYPE, CREATE, HSQLDB.DEFAULT_TABLE_TYPE, PAGE_STORE, CACHE_TYPE, FILE_LOCK, DB_CLOSE_ON_EXIT, AUTO_SERVER, AUTO_SERVER_PORT, AUTO_RECONNECT, ASSERT, ACCESS_MODE_DATA, OPEN_NEW, JMX, PAGE_SIZE, RECOVER, NAMES, SCHEMA, DATESTYLE, SEARCH_PATH, SCHEMA_SEARCH_PATH, LOGSIZE"; SQL statement:
[info] SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO" [42001-172]
[info]   at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
[info]   at org.h2.message.DbException.get(DbException.java:169)
[info]   at org.h2.message.DbException.getSyntaxError(DbException.java:194)
[info]   at org.h2.command.Parser.getSyntaxError(Parser.java:491)
[info]   at org.h2.command.Parser.parseSet(Parser.java:4676)
[info]   at org.h2.command.Parser.parsePrepared(Parser.java:407)
[info]   at org.h2.command.Parser.parse(Parser.java:279)
[info]   at org.h2.command.Parser.parse(Parser.java:255)
[info]   at org.h2.command.Parser.prepareCommand(Parser.java:218)
[info]   at org.h2.engine.Session.prepareLocal(Session.java:425)

So slick seems to use SQL commands not supported by H2 without MODE=MySQL (or am I wrong here?)

Using

"jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS \"public\"\\;"

results in the same error as if MODE=MySQL weren't present (so exactly the error shown in the box above)

È stato utile?

Soluzione

Set flyway.schemas to PUBLIC (all caps) and you should be fine. (I hope :-) )

Altri suggerimenti

this line in application.properties work with or withor mysql mode

spring.datasource.url=jdbc:h2:mem:test;MODE=MYSQL;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS \"public\"\\;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top