Database / Liquibase interview questions
What is a changeSet in Liquibase and how is it identified?
A changeSet is the atomic unit of change in Liquibase — it contains one or more related database operations (create table, add column, insert data, etc.) that should be applied together as a single migration step. Each changeSet is uniquely identified by the combination of three attributes: id, author, and the changeLog file path. Liquibase uses this three-part key to track whether a given changeSet has already been applied in a particular database.
The id is a free-form string — it can be a sequential number (1, 2, 3), a timestamp (20240115-001), or a descriptive slug (add-email-column). The author is usually the developer's name or username. The file path is recorded automatically from the location of the changeLog file on the classpath or filesystem.
<changeSet id="20240115-add-phone" author="bob"> <addColumn tableName="customer"> <column name="phone" type="VARCHAR(20)"/> </addColumn> <rollback> <dropColumn tableName="customer" columnName="phone"/> </rollback> </changeSet>
A critical rule: once a changeSet has been applied to any database (especially production), you must never modify its content. If the content of an applied changeSet changes, Liquibase will detect a checksum mismatch on the next run and fail with an error, preventing the migration from running. To make a correction, you always add a new changeSet rather than editing an existing one. This immutability guarantee is what makes the change history trustworthy.
More Related questions...