Database / Liquibase interview questions
How do you write Liquibase changeLogs in YAML format?
YAML is a supported Liquibase changeLog format that many teams prefer for its readability compared to verbose XML. The structure maps directly to the XML model — databaseChangeLog is the root, containing a list of changeSet entries, each with an id, author, and a list of changes.
databaseChangeLog: - changeSet: id: 1 author: lena changes: - createTable: tableName: product columns: - column: name: id type: BIGINT autoIncrement: true constraints: primaryKey: true nullable: false - column: name: name type: VARCHAR(200) constraints: nullable: false - column: name: price type: DECIMAL(10, 2) - changeSet: id: 2 author: lena context: prod changes: - addColumn: tableName: product columns: - column: name: sku type: VARCHAR(50) rollback: - dropColumn: tableName: product columnName: sku
YAML changeLogs support all the same features as XML: preconditions, contexts, labels, rollback, include/includeAll. The root changeLog file uses the same include mechanism:
databaseChangeLog: - includeAll: path: db/changelog/releases/v1.0/ - includeAll: path: db/changelog/releases/v1.1/
One common pitfall with YAML changeLogs: YAML is whitespace-sensitive, and incorrect indentation causes silent parsing errors or wrong structure interpretation. Use a YAML linter or IDE plugin that validates structure. Also note that the default Spring Boot changeLog file is YAML format (db.changelog-master.yaml), so new Spring Boot projects automatically use YAML unless configured otherwise.
More Related questions...