Kam*_*ski 4 java postgresql liquibase
我正在尝试在我的应用程序代码中运行 Liquibase。问题是在公共模式中创建了新表 ale,我如何将 liquibase 指向 Postgres 中的不同模式。
Liquibase liquibase = null;
Connection connection = null;
try {
connection = DB.getConnection();
liquibase = new Liquibase(CHANGELOG_FILE, new FileSystemResourceAccessor(), new JdbcConnection(connection));
//change default schema here
liquibase.update(STAGE);
} catch (LiquibaseException e) {
} finally {
if (connection != null) {
try {
connection.rollback();
connection.close();
} catch (SQLException e) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
这可以使用该方法来完成liqubase.database.Database::setDefaultSchema。例如:
val dbUrl = "jdbc:h2:~/aviary-db/dev;MODE=MySQL;DATABASE_TO_UPPER=false;IGNORECASE=TRUE;INIT=create schema if not exists aviary;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=2"
Connection conn = DriverManager.getConnection(dbUrl, user, password)
val dbConnection = JdbcConnection(conn)
val database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(dbConnection)
database.defaultSchemaName = "schema_name"
val liquibase = Liquibase("db/db-changelog.xml", ClassLoaderResourceAccessor(), database)
liquibase.update("")
Run Code Online (Sandbox Code Playgroud)
还值得注意的是,您可以用来setLiquibaseSchemaName决定 liquibase 将用于其内部表databasechangelog和databasechangeloglock.
| 归档时间: |
|
| 查看次数: |
22893 次 |
| 最近记录: |