Database / Liquibase interview questions
What are Liquibase tags and how do you use rollback to a tag?
A tag in Liquibase is a named marker you apply to the current state of DATABASECHANGELOG — a named checkpoint that records exactly which changeSets have been applied at the time of tagging. Tags are used as rollback targets: instead of counting changeSets or specifying a date, you roll back to a named release like v2.3.0.
You create a tag in two ways:
Via the CLI before a deployment:
liquibase tag v2.3.0
Inline in the changeLog using the tagDatabase change type:
<changeSet id="tag-v2.3.0" author="release-bot"> <tagDatabase tag="v2.3.0"/> </changeSet>
Including the tag as a changeSet is the preferred approach in automated pipelines because it ensures the tag is always created at exactly the right point in the changeLog regardless of when the deployment runs. The CLI approach requires the operator to run the tag command before the update, which is easy to forget.
To roll back to a tag:
liquibase rollback v2.3.0
This reverses all changeSets applied after the tag point, in reverse order. Before executing, you can preview what would happen:
liquibase rollbackSQL v2.3.0
A good practice for CI/CD pipelines is tagging the database with the release version at the start of every deployment. If the deployment fails partway through, rolling back to the previous tag restores the exact schema that was stable before the release.
More Related questions...