我正在尝试稍微笨拙的数据库迁移,我正在使用存储过程来更新我的应用程序表中的某些行。如果我使用mysql命令行工具或Sequel Pro执行它,存储过程运行正常,但是如果我尝试使用数据库迁移插件运行它,它就不会运行。
看起来liquibase支持存储过程,但数据库迁移插件似乎爆炸了。有谁知道这是否有效?
错误(和完整的存储过程)如下所示:
2014-03-08 09:05:21,693 [localhost-startStop-1] INFO liquibase - ChangeSet changelog_fb_contactForm_2_add_new_enquiry_roles.groovy::1393960870500-1::rcgeorge23 ran successfully in 6671ms
| Error 2014-03-08 09:05:21,704 [localhost-startStop-1] ERROR liquibase - Change Set changelog_fb_contactForm_3_add_enquiry_flexible_model_definition_to_existing_organisations.groovy::1393960870500-1::rcgeorge23
failed. Error: Error executing SQL DELIMITER //
CREATE PROCEDURE ABC()
BEGIN
REPEAT
set @organisationConfigurationId = (select id from organisation_configuration oc where oc.enquiry_flexible_model_definition_id is null limit 1);
insert into flexible_model_definition (`version`, `name`) values ('0', 'enquiry.flexible.model');
set @newlyInsertedEnquiryFlexibleModelDefinitionId = LAST_INSERT_ID();
update organisation_configuration oc set oc.enquiry_flexible_model_definition_id = @newlyInsertedEnquiryFlexibleModelDefinitionId where oc.id = @organisationConfigurationId
;
UNTIL 0 = (select count(*) from organisation_configuration oc where oc.enquiry_flexible_model_definition_id is null)
END REPEAT;
END //: 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 'DELIMITER //
CREATE PROCEDURE ABC()
BEGIN
REPEAT
set @organis' at line 1
Message: Error executing SQL DELIMITER //
CREATE PROCEDURE ABC()
BEGIN
REPEAT
set @organisationConfigurationId = (select id from organisation_configuration oc where oc.enquiry_flexible_model_definition_id is null limit 1);
insert into flexible_model_definition (`version`, `name`) values ('0', 'enquiry.flexible.model');
set @newlyInsertedEnquiryFlexibleModelDefinitionId = LAST_INSERT_ID();
update organisation_configuration oc set oc.enquiry_flexible_model_definition_id = @newlyInsertedEnquiryFlexibleModelDefinitionId where oc.id = @organisationConfigurationId
;
UNTIL 0 = (select count(*) from organisation_configuration oc where oc.enquiry_flexible_model_definition_id is null)
END REPEAT;
END //: 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 'DELIMITER //
CREATE PROCEDURE ABC()
BEGIN
REPEAT
set @organis' at line 1
Line | Method
->> 62 | execute in liquibase.executor.jvm.JdbcExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 104 | execute in ''
| 1091 | execute . . . . . . . . . . . in liquibase.database.AbstractDatabase
| 1075 | executeStatements in ''
| 317 | execute . . . . . . . . . . . in liquibase.changelog.ChangeSet
| 27 | visit in liquibase.changelog.visitor.UpdateVisitor
| 58 | run . . . . . . . . . . . . . in liquibase.changelog.ChangeLogIterator
....
答案 0 :(得分:1)
在定义存储过程时尝试使用splitStatements
,例如:
sqlFile path:'my_stored_procedure.sql', splitStatements: false
否则,数据库迁移插件将尝试变得聪明并拆分您的语句,这会破坏您的定义。
答案 1 :(得分:-1)
runOnChange =' true' 配置强制插件检查更改集是否已更改,而不是仅仅检查它是否已运行一次,因此可以跳过它。
默认情况下,文件中的sql语句被拆分;为了避免这种情况,请使用 splitStatements =' false' 配置以确保读取完整的创建过程脚本作为一个而不是拆分它;为每个单独的sql语句里面。
示例:强>
changeSet(author: "Rahul", id: "1435600003872-128", runOnChange: "true") {
sql("DROP PROCEDURE IF EXISTS BestCustomers;")
sqlFile(path: "../sql/BestCustomers.sql", splitStatements: false)
}
BestCustomers.sql的代码:
CREATE PROCEDURE `BestCustomers`(
//Input params here
)
BEGIN
//Sql scripts here ;
END
可以找到分步指南here。
赞美Rahul Babu。