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