Applies to
- Liquibase Pro
- Liquibase Open Source (Community)
Summary
Liquibase is a powerful database schema change management tool. It tracks and applies database changesets using a changelog file. Occasionally, you might encounter a scenario where older scripts (changesets) in your changelog have already been executed outside Liquibase, and you want to skip them without reapplying or causing conflicts.
Liquibase provides a utility, changelogSync, to mark changesets as executed without running them. This ensures consistency between your changelog file and the target database.
Environment Conditions
- Any version of Liquibase Pro or Open Source
How to skip an executed script
There are two ways to skip a changeset that has already been deployed.
Changelog-sync
The changelog-sync command syncs all eligible changesets to deploy in the changelog file to the DATABASECHANGELOG table. It doesn't execute the SQL when using this command.
One helpful attribute with the changelog-sync is the label attribute. You can go through your changesets and give any changeset that has been manually run a specific label to indicate the SQL has already been executed in the database.
When performing the changelog sync, you would provide that label, and Liquibase will only sync those changesets with the specified label.
Example
liquibase changelog-sync --label-filter=appliedManually --changelog-file=example-changelog.xml
Note: The changelog-sync command should be used carefully and with caution. Any undeployed changes will be marked as deployed.
Ignore
Another solution is to add the ignore attribute to the changeset. If the changeset is set to be ignored, Liquibase will not pick up this changeset during the update command.
Example
--liquibase formatted sql
--changeset adrian:1 ignore:true
create table person (
name varchar(255)
);
Comments
0 comments
Article is closed for comments.