{"id":5673,"date":"2025-12-12T05:58:26","date_gmt":"2025-12-12T05:58:26","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=5673"},"modified":"2025-12-12T08:17:56","modified_gmt":"2025-12-12T08:17:56","slug":"few-notes-on-liquibase","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/few-notes-on-liquibase\/","title":{"rendered":"Few notes on Liquibase"},"content":{"rendered":"<p><strong class=\"ctaHeader3\">Why to use Liquibase?<\/strong><br \/>\nLiquibase simplifies &#8211; Database Version Control and Automation of Database Migrations<\/p>\n<p><strong>pom.xml<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;dependency&gt;\r\n   &lt;groupId&gt;org.liquibase&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;liquibase-core&lt;\/artifactId&gt;\r\n&lt;\/dependency&gt;\r\n<\/pre>\n<p><strong>Simple Liquibase Script Example?<\/strong><br \/>\n<strong>db.changelog-master.xml<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n&lt;databaseChangeLog\r\n        xmlns=&quot;http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog&quot;\r\n        xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\r\n        xsi:schemaLocation=&quot;http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog\r\n        http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog\/dbchangelog-4.15.xsd&quot;&gt;\r\n    &lt;include file=&quot;\/db\/changelog\/1-createtable-changeset.xml&quot;\/&gt;\r\n    &lt;include file=&quot;\/db\/changelog\/2-altertable-changeset.xml&quot;\/&gt;\r\n    &lt;include file=&quot;\/db\/changelog\/3-inserttable-changeset.xml&quot;\/&gt;\r\n    &lt;include file=&quot;\/db\/changelog\/4-storedprocedure-changeset.xml&quot;\/&gt;\r\n    &lt;include file=&quot;\/db\/changelog\/5-createtable-address-changeset.xml&quot;\/&gt;\r\n&lt;\/databaseChangeLog&gt;\r\n<\/pre>\n<p><strong>1-createtable-changeset.xml<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;databaseChangeLog\r\n        xmlns=&quot;http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog&quot;\r\n        xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\r\n        xsi:schemaLocation=&quot;http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog\r\n        http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog\/dbchangelog-4.15.xsd&quot;&gt;\r\n\r\n    &lt;!-- Create schema --&gt;\r\n    &lt;changeSet id=&quot;create-table&quot; author=&quot;mugil&quot;&gt;\r\n        &lt;createTable tableName=&quot;employee&quot; schemaName=&quot;empmgmt&quot;&gt;\r\n            &lt;column name=&quot;id&quot; type=&quot;INT&quot; autoIncrement=&quot;true&quot;&gt;\r\n                &lt;constraints primaryKey=&quot;true&quot; nullable=&quot;false&quot;\/&gt;\r\n            &lt;\/column&gt;\r\n            &lt;column name=&quot;emp_name&quot; type=&quot;VARCHAR(50)&quot;\/&gt;\r\n        &lt;\/createTable&gt;\r\n    &lt;\/changeSet&gt;\r\n&lt;\/databaseChangeLog&gt;\r\n<\/pre>\n<p><strong  class=\"ctaHeader3\">Does the whole script runs everytime in liquibase?<\/strong><br \/>\nNo. liquibase does not run the whole script all the time. liquibase  maintains a databasechangelog table internally. This table keeps track of the new scripts and already executed scripts in form of history table.<\/p>\n<p><strong  class=\"ctaHeader3\">How liquibase distinguish between script which is already executed and script which needs to be executed?<\/strong><br \/>\nliquibase ID, Author and Chanelog file name to uniquely generate a MD5 Checksum value. This unique value helps in distinguish between old script which is already executed a new script to be executed<\/p>\n<pre>\r\n<changeSet id=\"create-table\" author=\"mugil\">\r\n<\/pre>\n<p><strong  class=\"ctaHeader3\"> Is there a way I could run the script again in liquibase?<\/strong><br \/>\nYes. There is a way by deleting the MD5sum value in the database which makes the liquibase engine to run script again.  You can also delete all the rows in the liquibase change log table which makes the script to get executed one more time.<\/p>\n<p><strong>Is there a way to confirm changelog files executed when the application starts?<\/strong><br \/>\n2 Ways<\/p>\n<p>You can confirm from server log displayed at the time of server startup.<br \/>\n<img decoding=\"async\" src=\"https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2025\/12\/LiquibaseDateExecLog.png\" alt=\"\" \/><\/p>\n<p>You can also confirm from database change log table<br \/>\n<img decoding=\"async\" src=\"https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2025\/12\/LiquibaseDateExec.png\" alt=\"\" \/><\/p>\n<p><strong  class=\"ctaHeader3\"> How to run a script again and again in liquibase?<\/strong><br \/>\nBy using <em>runAlways=&#8221;true&#8221;<\/em> in changeset. Liquibase ignores the DATABASECHANGELOG execution history for that changeset. Every run applies the SQL, even if identical.<br \/>\n<img decoding=\"async\" src=\"https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2025\/12\/LiquibaseDBChange.png\" alt=\"\" \/><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;changeSet id=&quot;insert_seed_data&quot; author=&quot;dev&quot; runAlways=&quot;true&quot;&gt;\r\n    &lt;insert tableName=&quot;config&quot;&gt;\r\n        &lt;column name=&quot;key&quot; value=&quot;last_updated&quot;\/&gt;\r\n        &lt;column name=&quot;value&quot; value=&quot;NOW()&quot;\/&gt;\r\n    &lt;\/insert&gt;\r\n&lt;\/changeSet&gt;\r\n<\/pre>\n<p><strong  class=\"ctaHeader3\">When to use runOnChange parameter in changeset?<\/strong><br \/>\nIf you are making changes to view or stored procedure then use runOnChange set to true. Liquibase ignores the DATABASECHANGELOG execution history for that changeset. Every run applies the SQL, even if identical.<\/p>\n<p><strong  class=\"ctaHeader3\">When to use runOnChange parameter in changeset?<\/strong><br \/>\nIf you are making changes to view or stored procedure then use runOnChange set to true. Liquibase ignores the DATABASECHANGELOG execution history for that changeset. Every run applies the SQL, even if identical.<\/p>\n<p><strong>Other Notes:<\/strong><br \/>\nYou can confirm scripts that would be executed by using liquibase:updateSQL which generates list of scripts to be executed. <\/p>\n<p><a href=\"https:\/\/bitbucket.org\/Mugil\/codesnippets\/src\/TestContainerForDBTesting\/\">Code Repo<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why to use Liquibase? Liquibase simplifies &#8211; Database Version Control and Automation of Database Migrations pom.xml &lt;dependency&gt; &lt;groupId&gt;org.liquibase&lt;\/groupId&gt; &lt;artifactId&gt;liquibase-core&lt;\/artifactId&gt; &lt;\/dependency&gt; Simple Liquibase Script Example? db.changelog-master.xml &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;databaseChangeLog xmlns=&quot;http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog\/dbchangelog-4.15.xsd&quot;&gt; &lt;include file=&quot;\/db\/changelog\/1-createtable-changeset.xml&quot;\/&gt; &lt;include file=&quot;\/db\/changelog\/2-altertable-changeset.xml&quot;\/&gt; &lt;include file=&quot;\/db\/changelog\/3-inserttable-changeset.xml&quot;\/&gt; &lt;include file=&quot;\/db\/changelog\/4-storedprocedure-changeset.xml&quot;\/&gt; &lt;include file=&quot;\/db\/changelog\/5-createtable-address-changeset.xml&quot;\/&gt; &lt;\/databaseChangeLog&gt; 1-createtable-changeset.xml &lt;databaseChangeLog xmlns=&quot;http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog http:\/\/www.liquibase.org\/xml\/ns\/dbchangelog\/dbchangelog-4.15.xsd&quot;&gt; &lt;!&#8211; Create schema &#8211;&gt; &lt;changeSet&hellip; <a href=\"https:\/\/codethataint.com\/blog\/few-notes-on-liquibase\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[372],"tags":[],"class_list":["post-5673","post","type-post","status-publish","format-standard","hentry","category-java-tools"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=5673"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5673\/revisions"}],"predecessor-version":[{"id":5689,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5673\/revisions\/5689"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=5673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=5673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=5673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}