代码之家  ›  专栏  ›  技术社区  ›  unknown

在liquibase中定义插入查询的变更集

  •  21
  • unknown  · 技术社区  · 11 年前

    我有两张桌子如下:

    CREATE TABLE StudentMaster (
      sId      SERIAL,
      StudentName VARCHAR(50)
    );
    
    CREATE TABLE StudentClassMap (
      studnetId BIGINT UNSIGNED NOT NULL,
      studentClass VARCHAR(10),
      FOREIGN KEY (studnetId) REFERENCES StudentMaster (sId)
    );
    

    这是我的插入查询。

    INSERT INTO StudentMaster (studentName) values ('Jay Parikh');
    
    INSERT INTO StudentClassMap (studnetId, studentClass)
    values ((SELECT sId from StudentMaster where studentName='Jay Parikh'),
            'M.Sc. 1st Year');
    

    我想定义 变更集 中的thes查询 liquibase .

    对于第一个查询 变更集 将:

    <changeSet author="unknown" id="insert-example">
        <insert tableName="StudentMaster ">
            <column name="studentName" value="Jay Parikh"/>
        </insert>
    </changeSet>
    

    但我不知道如何定义 变更集 用于另一个查询。
    有什么帮助吗?提前感谢。

    1 回复  |  直到 11 年前
        1
  •  48
  •   Chris Williams    9 年前

    使用valueComputed属性:

    <changeSet author="unknown" id="insert-example-2">
        <insert tableName="StudentClassMap">
            <column name="studentId" valueComputed="(SELECT sId from StudentMaster where studentName='Jay Parikh')"/>
            <column name="studentClass" value="McSc. 1st Year"/>
        </insert>
    </changeSet>
    
    推荐文章