☰ See All Chapters |
Liquibase change log file
If we have multiple change log files form different developers, instead of executing liquibase multiple times we can create a single liquibase file having group of includes of all change log files. When this grouped change log files is executed all the changes from all the included change log files will be updated to database. This change log file is created by putting all changeSet inside databaseChangeLog.
databaseChangeLog is the root tag in change log file as given below:
changelog_1.0.xml
<databaseChangeLog xmlns="https://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<changeSet id="create_student" author="manu.manjunatha"> <createTable tableName="student"> <column name="id" type="int"> <constraints primaryKey="true" nullable="false" /> </column> <column name="name" type="varchar(50)"> <constraints nullable="false" /> </column> </createTable> </changeSet>
</databaseChangeLog> |
changelog_1.1.xml
<databaseChangeLog xmlns="https://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<changeSet id="create_employee" author="manu.manjunatha"> <createTable tableName="employee"> <column name="id" type="int"> <constraints primaryKey="true" nullable="false" /> </column> <column name="firstname" type="varchar(50)"> <constraints nullable="false" /> </column> <column name="lastname" type="varchar(50)"> <constraints nullable="false" /> </column> </createTable> </changeSet>
</databaseChangeLog> |
changelog_grouped.xml
<databaseChangeLog xmlns="https://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<include file="changelog_1.0.xml"/> <include file="changelog_1.1.xml"/>
</databaseChangeLog> |
liquibase.properties
driver=com.mysql.cj.jdbc.Driver url=jdbc:mysql://localhost:3306/liquibase username=root password=root |
Open command prompt for the folder having changelog_1.0.xml and liquibase.properties file and execute the below command:
liquibase --defaultsFile=C:\Liquibase_example\liquibase.properties --changeLogFile=C:\Liquibase_example\changelog_grouped.xml update
Check the database for output
All Chapters