Define Changeset for insert query in liquibase

穿精又带淫゛_ 提交于 2019-12-07 12:37:32

问题


I have two table as following :

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)
);

This is my insert query.

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');

I want to define ChangeSet for thes queries in liquibase.

For First query ChangeSet will be :

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

But I don't know how to define ChangeSet for another query.
Any help ? Thanks in advance.


回答1:


Use the valueComputed attribute:

<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>


来源:https://stackoverflow.com/questions/22356313/define-changeset-for-insert-query-in-liquibase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!