Junior — Middle
Have you created scripts for automating database migrations using Liquibase?
sobes.tech AI
Answer from AI
Yes, to automate database migrations with Liquibase, scripts are usually created in XML, YAML, JSON, or SQL formats that describe database schema changes (changelogs). These scripts allow applying changes sequentially, rolling them back, and controlling the database version.
An example of a simple changelog in XML for creating a table:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet id="1" author="user">
<createTable tableName="person">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(255)"/>
</createTable>
</changeSet>
</databaseChangeLog>
This script can be run via the command line or integrated into the build process of a project for automatic migration application.