背景:今天在部署sql代码的时候,发现以前一直使用的判断字段存在的方式不起作用了,如下:
<preConditions onFail="MARK_RAN" >
<not>
<columnExists schemaName="${schema.name}" tableName="prize" columnName="reward_service_category" />
</not>
</preConditions>
在网上找了好久方法,liquibase的资料太少,最后决定使用存储过程去判断,这种方法确实好用。
delimiter //
create procedure add_more_to_logins() begin
if not exists(select * from information_schema.COLUMNS
where table_name = 'a' AND column_name = 'b' and table_schema = database()) THEN
alter table a add `is_mobile` tinyint(1) null after reason;
end if;
END;
//
delimiter ;
本文转自chenzudao51CTO博客,原文链接: http://blog.51cto.com/victor2016/1877797,如需转载请自行联系原作者