我通过提供输入ddl
使用liquibase
创建了data base change log
脚本。
代码看起来像这样
private void toSQL(DatabaseChangeLog d)
throws DatabaseException, LiquibaseException, UnsupportedEncodingException, IOException {
FileSystemResourceAccessor fsOpener = new FileSystemResourceAccessor();
CommandLineResourceAccessor clOpener = new CommandLineResourceAccessor(this.getClass().getClassLoader());
CompositeResourceAccessor fileOpener = new CompositeResourceAccessor(new ResourceAccessor[] { fsOpener, clOpener });
Database database = CommandLineUtils.createDatabaseObject(fileOpener, this.url, this.username, this.password, this.driver,
this.defaultCatalogName, this.defaultSchemaName, Boolean.parseBoolean(this.outputDefaultCatalog),
Boolean.parseBoolean(this.outputDefaultSchema), this.databaseClass,
this.driverPropertiesFile, this.propertyProviderClass, this.liquibaseCatalogName,
this.liquibaseSchemaName, this.databaseChangeLogTableName, this.databaseChangeLogLockTableName);
Liquibase liquibase=new Liquibase(d, null, database);
liquibase.update(new Contexts(this.contexts), new LabelExpression(this.labels), getOutputWriter());
}
而我的liquibase.properties
就是这样的
url=jdbc\:sqlserver\://server\:1433;databaseName\=test
username=test
password=test@123
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
referenceUrl=hibernate:spring:br.com.company.vacation.domain?dialect=org.hibernate.dialect.SQLServer2008Dialect
正如你所看到的,Liquibase期待很多db
参数,如url
,username
,password
,driver
,我将无法提供。
如何在不提供任何参数的情况下实现此目的。可能吗?
不,这是不可能的。如果您希望liquibase与数据库进行交互,则必须告诉它如何连接到该数据库。
我对liquibase
的offline mode
操作进行了一些调查。它是这样的。
在离线模式下运行仅支持updateSql
,rollbackSQL
,tag
和tagExists
。它不支持直接update, diff, or preconditions
,因为没有任何实际更新或状态检查。
离线数据库使用offline:DATABASE_TYPE?param1=value1&aparam2=value2
的url语法“连接”。
以下代码就足够了
this.url=offline:postgres?param1=value1&aparam2=value2;
this.driver=null;
this.username=null;
this.password=null;
因此不提供db详细信息。离线网址可以从商店类型中组成。