Spring boot 模式';SA';不存在
获取错误,说明架构“SA”不存在。从H2过渡到Derby,所以我保留了每个人都使用的原始SA用户名。我的意图是使用Derby作为内存中数据库来建模DB/2 LUW。在主代码中,DB/2端加载了Flyway迁移。我也希望对内存中的数据库执行同样的操作,尝试了H2,但停止了,因为一些CREATETABLE语句在H2下无法工作,即使在DB/2兼容模式下也是如此 注意:由于IP原因,我更改了一些路径 基本上,它似乎试图执行迁移,但失败了,因为没有SA模式。我可以理解没有SA模式,但这不是H2的问题,它只是创建了它。如何在Flyway之前创建模式?我不想更改我的flyway脚本 堆栈跟踪是:Spring boot 模式';SA';不存在,spring-boot,spring-data-jpa,spring-data,derby,flyway,Spring Boot,Spring Data Jpa,Spring Data,Derby,Flyway,获取错误,说明架构“SA”不存在。从H2过渡到Derby,所以我保留了每个人都使用的原始SA用户名。我的意图是使用Derby作为内存中数据库来建模DB/2 LUW。在主代码中,DB/2端加载了Flyway迁移。我也希望对内存中的数据库执行同样的操作,尝试了H2,但停止了,因为一些CREATETABLE语句在H2下无法工作,即使在DB/2兼容模式下也是如此 注意:由于IP原因,我更改了一些路径 基本上,它似乎试图执行迁移,但失败了,因为没有SA模式。我可以理解没有SA模式,但这不是H2的问题,它只
SQL State : 42Y07
Error Code : 20000
Message : Schema 'SA' does not exist
at org.flywaydb.core.internal.database.base.Connection$2.call(Connection.java:171)
at org.flywaydb.core.internal.database.base.Connection$2.call(Connection.java:165)
at org.flywaydb.core.internal.jdbc.TransactionTemplate.execute(TransactionTemplate.java:74)
at org.flywaydb.core.internal.database.base.Connection.restoreOriginalSchema(Connection.java:165)
at org.flywaydb.core.internal.database.base.Connection.close(Connection.java:159)
at org.flywaydb.core.internal.database.base.Database.close(Database.java:488)
at org.flywaydb.core.Flyway.execute(Flyway.java:1731)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1356)
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 47 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: Schema 'SA' does not exist
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.execute(Unknown Source)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
at org.flywaydb.core.internal.jdbc.JdbcTemplate.execute(JdbcTemplate.java:215)
at org.flywaydb.core.internal.database.derby.DerbyConnection.doChangeCurrentSchemaOrSearchPathTo(DerbyConnection.java:48)
at org.flywaydb.core.internal.database.base.Connection$2.call(Connection.java:169)
... 57 common frames omitted
Caused by: org.apache.derby.iapi.error.StandardException: Schema 'SA' does not exist
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getSchemaDescriptor(Unknown Source)
at org.apache.derby.impl.sql.execute.SetSchemaConstantAction.executeConstantAction(Unknown Source)
at org.apache.derby.impl.sql.execute.MiscResultSet.open(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
... 65 common frames omitted**strong text**
添加了POM.xml依赖项
<properties>
<derby-version>10.14.1.0</derby-version>
</properties>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>${derby-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<version>${derby-version}</version>
<scope>test</scope>
</dependency>
src/test/acceptance/java/com/mycompany/cost/ssc/file/generator/system/FileGeneratorSystem.java
public class FileGeneratorSystem {
protected String basePath;
protected JdbcTemplate jdbcTemplate;
private DataSource dataSource;
private String dbUrl;
private String userName;
private String password;
private String driverClassName;
public FileGeneratorSystem() {
dbUrl = "jdbc:derby:memory:testdb;create=true";
userName = "sa";
password = "sa";
driverClassName = "org.apache.derby.jdbc.EmbeddedDriver";
setEnvironmentVariables();
createDbConnection();
executeScript("src/test/acceptance/resources/sql/initial_test_setup.sql");
}
private void setEnvironmentVariables() {
basePath = System.getProperty("file-generator.test.files.path", "src/test/acceptance/resources/files/");
}
private String getEnvironment(String name, String defaultValue) {
String result = System.getenv(name);
if(result==null) {
result = defaultValue;
}
return result;
}
private void createDbConnection() {
dataSource = buildDataSource();
jdbcTemplate = new JdbcTemplate(dataSource);
}
private DataSource buildDataSource() {
return DataSourceBuilder.create()
.url(dbUrl)
.username(userName)
.password(password)
.driverClassName(driverClassName)
.type(SingleConnectionDataSource.class)
.build();
}
public void executeScript(String scriptLocation) {
Resource resource = new FileSystemResource(scriptLocation);
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(resource);
databasePopulator.execute(dataSource);
}
public RunResult fetchExecutionResult() {
RunResult result = jdbcTemplate.queryForObject(
"SELECT * FROM FILE_GENERATOR.RUN_RESULT WHERE RUN_RESULT_ID = (" +
"SELECT MAX(RUN_RESULT_ID) FROM FILE_GENERATOR.RUN_RESULT" +
")", new RunResultRowMapper());
return result;
}
public void runFileGenerator() {
BlueCostSSCFileGeneratorApplication.main(new String[]{
"--debug=true",
"--spring.datasource.url=" + dbUrl,
"--spring.datasource.username=" + userName,
"--spring.datasource.password=" + password,
"--spring.datasource.driver-class-name" + driverClassName,
"--spring.jpa.hibernate.dialect=org.hibernate.dialect.DerbyDialect",
"--spring.jpa.database-platform=org.hibernate.dialect.DerbyDialect",
"--spring.flyway.baseline-on-migrate=true",
"--spring.flyway.url="+dbUrl,
"--spring.flyway.user="+userName,
"--spring.flyway.password="+password,
"--spring.jpa.generate-ddl=true",
"--spring.jpa.database=default",
"--spring.jpa.show-sql=true",
"--spring.datasource.continue-on-error=false",
"--spring.jpa.hibernate.ddl-auto=update",
"--spring.jpa.hibernate.dialect=org.hibernate.dialect.DerbyDialect"
});
}
}
class RunResultRowMapper implements RowMapper<RunResult> {
@Override
public RunResult mapRow(ResultSet rs, int rowNum) throws SQLException {
ResultTypeConverter resultTypeConverter = new ResultTypeConverter();
RunResult runResult = new RunResult();
runResult.setResultType(resultTypeConverter.convertToEntityAttribute(rs.getString("RESULT_TYPE")));
runResult.setEbcdicFileName(rs.getString("EBCDIC_FILE_NAME"));
return runResult;
}
}
您正在寻找“设置模式”状态吗?
public class FileGeneratorSystem {
protected String basePath;
protected JdbcTemplate jdbcTemplate;
private DataSource dataSource;
private String dbUrl;
private String userName;
private String password;
private String driverClassName;
public FileGeneratorSystem() {
dbUrl = "jdbc:derby:memory:testdb;create=true";
userName = "sa";
password = "sa";
driverClassName = "org.apache.derby.jdbc.EmbeddedDriver";
setEnvironmentVariables();
createDbConnection();
executeScript("src/test/acceptance/resources/sql/initial_test_setup.sql");
}
private void setEnvironmentVariables() {
basePath = System.getProperty("file-generator.test.files.path", "src/test/acceptance/resources/files/");
}
private String getEnvironment(String name, String defaultValue) {
String result = System.getenv(name);
if(result==null) {
result = defaultValue;
}
return result;
}
private void createDbConnection() {
dataSource = buildDataSource();
jdbcTemplate = new JdbcTemplate(dataSource);
}
private DataSource buildDataSource() {
return DataSourceBuilder.create()
.url(dbUrl)
.username(userName)
.password(password)
.driverClassName(driverClassName)
.type(SingleConnectionDataSource.class)
.build();
}
public void executeScript(String scriptLocation) {
Resource resource = new FileSystemResource(scriptLocation);
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(resource);
databasePopulator.execute(dataSource);
}
public RunResult fetchExecutionResult() {
RunResult result = jdbcTemplate.queryForObject(
"SELECT * FROM FILE_GENERATOR.RUN_RESULT WHERE RUN_RESULT_ID = (" +
"SELECT MAX(RUN_RESULT_ID) FROM FILE_GENERATOR.RUN_RESULT" +
")", new RunResultRowMapper());
return result;
}
public void runFileGenerator() {
BlueCostSSCFileGeneratorApplication.main(new String[]{
"--debug=true",
"--spring.datasource.url=" + dbUrl,
"--spring.datasource.username=" + userName,
"--spring.datasource.password=" + password,
"--spring.datasource.driver-class-name" + driverClassName,
"--spring.jpa.hibernate.dialect=org.hibernate.dialect.DerbyDialect",
"--spring.jpa.database-platform=org.hibernate.dialect.DerbyDialect",
"--spring.flyway.baseline-on-migrate=true",
"--spring.flyway.url="+dbUrl,
"--spring.flyway.user="+userName,
"--spring.flyway.password="+password,
"--spring.jpa.generate-ddl=true",
"--spring.jpa.database=default",
"--spring.jpa.show-sql=true",
"--spring.datasource.continue-on-error=false",
"--spring.jpa.hibernate.ddl-auto=update",
"--spring.jpa.hibernate.dialect=org.hibernate.dialect.DerbyDialect"
});
}
}
class RunResultRowMapper implements RowMapper<RunResult> {
@Override
public RunResult mapRow(ResultSet rs, int rowNum) throws SQLException {
ResultTypeConverter resultTypeConverter = new ResultTypeConverter();
RunResult runResult = new RunResult();
runResult.setResultType(resultTypeConverter.convertToEntityAttribute(rs.getString("RESULT_TYPE")));
runResult.setEbcdicFileName(rs.getString("EBCDIC_FILE_NAME"));
return runResult;
}
}
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.flywaydb.core.Flyway;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
@RunWith(Cucumber.class)
@SpringBootTest
@TestPropertySource(locations="classpath:application-test.properties")
@CucumberOptions(
features = "src/test/acceptance/" ,
plugin = {"pretty", "html:target/report/cucumber.html",
"json:target/report/cucumber.json",
"junit:target/report/cucumber.xml"},
glue = { "com.mycompany.cost.ssc.file.generator" }
)
public class AcceptanceRunnerWithSpring {
@Autowired
private Flyway flyway;
@Test
public void skipAutomaticAndTriggerManualFlywayMigration() {
flyway.migrate();
}
}