liquibase - 将存储过程的嵌入式 sql 文件用作 Liquibase 变更集的实际示例
问题描述
我可以举一个关于如何将嵌入式 sql 文件用于存储过程的示例吗?应该使用带有 --changeset 语法的变更日志中的 sql 嵌入文件。
我试过查看文档,它显示了如何编写变更集,但不是特别针对存储过程,而且我没有看到实际的源 sql 文件。
解决方案
带有存储过程的示例嵌入式 sql 文件:
DROP FUNCTION IF EXISTS split_token;
//
CREATE FUNCTION split_token(txt text, delimiter_text VARCHAR(255), token_index INT UNSIGNED) RETURNS TEXT DETERMINISTIC
BEGIN
/*! Return substring by index in delimited text */
IF CHAR_LENGTH(delimiter_text) = ''
THEN return SUBSTRING(txt, token_index, 1);
ELSE return SUBSTRING_INDEX(SUBSTRING_INDEX(txt, delimiter_text, token_index),delimiter_text,-1);
END IF;
END
//
DROP FUNCTION IF EXISTS split_token2;
//
CREATE FUNCTION split_token2(txt text, delimiter_text VARCHAR(255), token_index INT UNSIGNED) RETURNS TEXT DETERMINISTIC
BEGIN
/*! Return substring by index in delimited text */
IF CHAR_LENGTH(delimiter_text) = ''
THEN return SUBSTRING(txt, token_index, 1);
ELSE return SUBSTRING_INDEX(SUBSTRING_INDEX(txt, delimiter_text, token_index),delimiter_text,-1);
END IF;
END
回滚脚本如下所示:
DROP FUNCTION IF EXISTS split_token;
//
DROP FUNCTION IF EXISTS split_token2;
变更日志如下所示:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.8.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<!-- <changeSet author="SteveZ" id="external-sql+rollback-script-example" context="QA" labels="Jira1000">
<sqlFile dbms="mysql" splitStatements="true" endDelimiter="//" stripComments="true" path="objects/function/split_token.sql"/>
<rollback>
<sqlFile dbms="mysql" splitStatements="true" endDelimiter="//" stripComments="true" path="objects/function/split_token_rollback.sql"/>
</rollback>
</changeSet> -->
....
</databaseChangeLog>
推荐阅读
- pgadmin-4 - pgAdmin 4 覆盖不会关闭
- tensorflow - TFLiteConverter.from_saved_model RuntimeError:在 SavedModel 中找不到与标签 {'serve'} 关联的 MetaGraphDef
- typescript - 如何使用打字稿在vue类样式组件中双向绑定v-model对象
- javascript - 如何将多个按钮数据传递给 1 个查询
- javascript - 如何使用 javascript 显示隐藏/显示菜单?
- python - 将字符串保存在 ast.literal_eval 到 dict
- c - C预处理器为多种类型赋值
- c - 使用 ncurses 将光标卡在板上(编程 SOS 游戏)
- python - 将 TensorFlow 1 层迁移到 TensorFlow 2
- python - 熊猫中多列的逐列最大值的逐列计数