0

我想使用 Liquibase 创建和更改数据库用户。以下是对 Oracle DB 执行此操作的 SQL 查询。

change password:
ALTER USER ADMIN IDENTIFIED BY ${user.password};
create user:
CREATE USER appuser IDENTIFIED BY ${user.password};

我想让密码参数化,但changelog Property Substitution在 SQL 格式中不可用。

我选择 XML 作为后备选项,但无法将上述查询转换为 Liquibase XML 格式。我需要帮助将更改/创建用户查询转换为 XML。

4

1 回答 1

1

您可以在 XML 变更集中使用 SQL 标记,并使用该标记编写任何 SQL 查询,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

    <changeSet author="authorName" id="some-unique-id" dbms="${dbType}">
       <sql endDelimiter=";" splitStatements="true" stripComments="true">
            **My SQL query/ transactional logic goes here**
            CREATE USER appuser IDENTIFIED BY ${user.password};
       </sql>
    </changeSet>
    
</databaseChangeLog>

然后您可以将Liquibase 更改日志属性替换与密码值一起使用。使用 SQL 标记将允许您执行任何 SQL 查询(当然以正确的语法),而不必担心 liquibase 变更集的 XML 语法。

有关属性替换的更多详细信息,请查看我在这篇文章中的回答

于 2021-04-21T13:02:19.793 回答