|
我正在为MySQL首先设置数据库liquibase maven项目。已做好创建触发器的工作。2 P7 R* R/ h; k' }
我相信这是liquibase和JDBC多语句无法正确处理SQL但我找不到缺少的内容。
: U" m( f2 k$ I# t这是我的pom依赖
& D+ h" x" o5 G org.liquibase liquibase-parent 3.5.3 pom org.liquibase liquibase-core 3.5.3 mysql mysql-connector-java 5.1.46 org.liquibase liquibase-maven-plugin 3.6.3 这是我的liquibase包含文件+ X! x. I9 r& A2 w W1 ]' |8 {$ W
drop trigger if exists ai_event_approval; 这是我的SQL文件
; q' B: o7 {" w3 {CREATE DEFINER ='evclient'@'%' TRIGGER ai_event_approval AFTER INSERT ON event_approval FOR EACH rowbegin insert into event_approval_log (rowAction, actionTs, event, requestorEmail, requestReason, statusType, approverUserId, approverReason, lastChangTs) values ('I current_timestamp(6) new.event, new.requestorEmail, new.requestReason, new.statusType, new.approverUserId, new.approverReason, new.lastChangTs);end;# DONE我期待设置splitStatements,stripComments和endDelimiter,我将获得liquibase来将整个SQL作为一个JDBC发送。. b3 l( U& \; W; N4 [
但是我收到了这个错误
' u- f" D5 C8 F' s; s! S! h! a; i[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.6.3:update (default) on project event-horizon-mysql: Error setting up or running Liquibase: Migration failed for change set /Users/lmtyler/OneDrive - Walmart Inc/workspace/code/event-horizon/event-horizon-mysql/src/main/java/resources/liquibase/schema/triggers/02__au_event_approval.sql::event_horizon_1_0_1::lmtyler:[ERROR] Reason: liquibase.exception.DatabaseException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 23 [Failed SQL: CREATE TRIGGER au_event_approval[ERROR] AFTER UPDATE[ERROR] ON event_approval[ERROR] FOR EACH row[ERROR] begin[ERROR] insert into event_approval_log (rowAction,[ERROR] actionTs,[ERROR] event,[ERROR] requestorEmail,[ERROR] requestReason,[ERROR] statusType,[ERROR] approverUserId,[ERROR] approverReason,[ERROR] lastChangTs)[ERROR] values ('U',[ERROR] current_timestamp(6),[ERROR] new.event,[ERROR] new.requestorEmail,[ERROR] new.requestReason,[ERROR] new.statusType,[ERROR] new.approverUserId,[ERROR] new.approverReason,[ERROR] new.lastChangTs)]
8 z% J9 B# [' ?; s; S [, k( ]% W 解决方案:
+ ?( @: M5 C( J9 P 加上一夜无眠@Jens我终于明白了这个问题。- Z' w" v) w/ h/ ]1 V# M/ d
首先,如果你看到我的帖子,这个错误不是我想的SQL错误AFTER INSERT这是错误的原因,但这是AFTER UPDATE
9 E% Z( K4 N2 A3 g1 C( N" K关键是确保设置splitStatements:false,endDelimiter而无需设置。
* n# P- m% l& B# z# W这是两个有效的例子:8 _" z: ?* Y( E* S
与此SQL文件
. y% B7 N( |6 U, d+ @; ~CREATE DEFINER ='evclient'@'%' TRIGGER ai_event_approval AFTER INSERT ON event_approval FOR EACH rowbegin insert into event_approval_log (rowAction, actionTs, event, requestorEmail, requestReason, statusType, approverUserId, approverReason, lastChangTs) values ('I', current_timestamp(6), new.event, new.requestorEmail, new.requestReason, new.statusType, new.approverUserId, new.approverReason, new.lastChangTs);end;这是使用SQL格式: [* U& }. N& {3 o1 @$ K+ L0 x8 X
--changeset lmtyler:event_horizon_1_0_1 dbms:mysql splitStatements:falseCREATE TRIGGER au_event_approval AFTER UPDATE ON event_approval FOR EACH rowbegin insert into event_approval_log (rowAction, actionTs, event, requestorEmail, requestReason, statusType, approverUserId, approverReason, lastChangTs) values ('U current_timestamp(6) new.event, new.requestorEmail, new.requestReason, new.statusType, new.approverUserId, new.approverReason, new.lastChangTs);end; |
|