在测试模式下使用flyway with play:找不到架构“public”

问题描述 投票:3回答:2

我在dev和prod模式下使用(成功)flyway-play插件。我也想在测试模式下使用它。文档说,它在测试模式下自动运行迁移。

我使用scala测试,我的测试用例包含在假的应用程序中

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"->""
))

运行测试用例时,自动迁移失败并显示“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)

这个错误究竟是什么意思?为什么使用公共模式?我的数据库配置定义“db.default”,而不是“db.public”。什么是公共架构?我没有在任何地方定义它。

关于如何使测试用例运行(或者至少更进一步)的任何想法?

编辑:

我发现提示(Schema related problems with Flyway / Spring and H2 embedded database)不在h2 db url中使用MODE = MySQL。不幸的是,我似乎需要它光滑。如果我不使用它,我会

[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)

所以光滑似乎使用H2不支持的SQL命令而没有MODE = MySQL(或者我错了吗?)

运用

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

导致相同的错误,如同MODE = MySQL不存在(所以错误地显示在上面的框中显示的错误)

playframework h2 slick flyway play-slick
2个回答
6
投票

将flyway.schemas设置为PUBLIC(全部大写),你应该没问题。 (我希望 :-) )


0
投票

application.properties中的这一行使用或使用mysql模式

spring.datasource.url=jdbc:h2:mem:test;MODE=MYSQL;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS \"public\"\\;
© www.soinside.com 2019 - 2024. All rights reserved.