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.
To generate a newer version of the changelog file with stored logic objects based on the current database state, you need to delete, rename, or move the Objects directory that was created by running the generate-changelog command previously. Then, you can run the generate-changelog command again.
The changeset tag is a unit of change that Liquibase executes on a database and which is used to group database Liquibase Change Types together. A list of changes created by multiple changesets are tracked in a changelog.
Liquibase Concepts Simply put – a changelog contains an ordered list of changesets, and a changeset contains a change. You and your team can specify database changes in one of four different changelog formats: SQL, XML, JSON, or YAML. And, you can even mix and match different types of changelogs, if desired.
Step 1: Add the tagDatabase Change Type to your changeset with the tag attribute as it is shown in the examples. Step 2: Deploy your changeset by running the update command. Now, you should see that the tag has been applied to the DATABASECHANGELOG table as a new changeset row.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With