我试图检查表是否存在,然后执行更改集。但这一先决条件似乎没有得到妥善执行。关于如何检查表是否存在和执行语句的任何建议?
Liquibase脚本:
databaseChangeLog:
- preConditions:
- onFail: MARK_RAN
- sqlCheck:
expectedResult: 1
sql: SELECT count(*) FROM information_schema.TABLES WHERE TABLE_NAME = TABLE_MAY_NOT_EXIST
- changeSet:
id: 1001001
author: upgrade_author
changes:
- sql:
sql: UPDATE MY_TABLE SET COL_A = (SELECT TOP 1 COL_A FROM TABLE_MAY_NOT_EXIST ORDER BY COL_A DESC)
stripComments: true
错误日志:
Caused by: liquibase.exception.DatabaseException: Table "TABLE_MAY_NOT_EXIST" not found; SQL statement:
UPDATE MY_TABLE SET COL_A = (SELECT TOP 1 COL_A FROM TABLE_MAY_NOT_EXIST ORDER BY COL_A DESC) [42102-197] [Failed SQL: UPDATE MY_TABLE SET COL_A = (SELECT TOP 1 COL_A FROM TABLE_MAY_NOT_EXIST ORDER BY COL_A DESC)]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:356) ~[liquibase-core-3.6.3.jar:na]
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:57) ~[liquibase-core-3.6.3.jar:na]
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:125) ~[liquibase-core-3.6.3.jar:na]
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1229) ~[liquibase-core-3.6.3.jar:na]
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1211) ~[liquibase-core-3.6.3.jar:na]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:600) ~[liquibase-core-3.6.3.jar:na]
我看您错过了liquibase的属性文件,您可以在这里找到编写liquibase属性文件的方法
同样,也可以按照下面的说明创建变更日志文件