CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-liquibase--liquibase-core

Liquibase is a tool for managing and executing database changes.

Pending
Overview
Eval results
Files

database-operations.mddocs/

Core Database Operations

This document covers the primary database migration and management operations provided by the main Liquibase class.

Imports

import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.database.DatabaseConnection;
import liquibase.resource.ResourceAccessor;
import liquibase.changelog.DatabaseChangeLog;
import liquibase.changelog.ChangeSet;
import liquibase.Contexts;
import liquibase.LabelExpression;
import liquibase.exception.LiquibaseException;
import liquibase.exception.DatabaseException;

import java.util.List;
import java.util.Date;
import java.util.Collection;
import java.io.Writer;
import java.io.PrintStream;

// Additional types for complete API coverage
import liquibase.changelog.ChangeSetStatus;
import liquibase.changelog.RanChangeSet;
import liquibase.change.CheckSum;
import liquibase.lockservice.DatabaseChangeLogLock;
import liquibase.structure.core.CatalogAndSchema;
import liquibase.changelog.visitor.DefaultChangeExecListener;
import liquibase.logging.Logger;
import liquibase.diff.DiffResult;
import liquibase.diff.compare.CompareControl;
import liquibase.diff.output.changelog.DiffToChangeLog;
import liquibase.serializer.ChangeLogSerializer;
import liquibase.structure.DatabaseObject;
import liquibase.command.CommandExecutionException;

Liquibase Class Construction

The main Liquibase class serves as the primary facade for all database operations.

/**
 * Create Liquibase instance with changelog file
 * @param changeLogFile Path to changelog file
 * @param resourceAccessor Resource accessor for file access
 * @param conn Database connection
 */
public Liquibase(String changeLogFile, ResourceAccessor resourceAccessor, DatabaseConnection conn) throws LiquibaseException

/**
 * Create Liquibase instance with database object
 * @param changeLogFile Path to changelog file  
 * @param resourceAccessor Resource accessor for file access
 * @param database Database instance
 */
public Liquibase(String changeLogFile, ResourceAccessor resourceAccessor, Database database)

/**
 * Create Liquibase instance with changelog object
 * @param changeLog Parsed changelog object
 * @param resourceAccessor Resource accessor for file access
 * @param database Database instance
 */
public Liquibase(DatabaseChangeLog changeLog, ResourceAccessor resourceAccessor, Database database)

Update Operations

Basic Updates

Execute database updates to apply pending changesets:

/**
 * Update database with all pending changesets
 */
public void update() throws LiquibaseException

/**
 * Update database with context filtering
 * @param contexts Comma-separated list of contexts
 */
public void update(String contexts) throws LiquibaseException

/**
 * Update database with contexts object
 * @param contexts Contexts for filtering changesets
 */
public void update(Contexts contexts) throws LiquibaseException

/**
 * Update database with contexts and labels
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 */
public void update(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Update database with full control
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering  
 * @param checkLiquibaseTables Whether to check Liquibase tracking tables
 */
public void update(Contexts contexts, LabelExpression labelExpression, boolean checkLiquibaseTables) throws LiquibaseException

Limited Updates

Execute a specific number of changesets or update to a specific tag:

/**
 * Update database with limited number of changesets
 * @param changesToApply Number of changesets to apply
 * @param contexts Comma-separated list of contexts
 */
public void update(int changesToApply, String contexts) throws LiquibaseException

/**
 * Update database with limited number of changesets (full control)
 * @param changesToApply Number of changesets to apply
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 */
public void update(int changesToApply, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Update database to specific tag
 * @param tag Target tag to update to
 * @param contexts Comma-separated list of contexts  
 */
public void update(String tag, String contexts) throws LiquibaseException

/**
 * Update database to specific tag (full control)
 * @param tag Target tag to update to
 * @param contexts Contexts for filtering changesets
 */
public void update(String tag, Contexts contexts) throws LiquibaseException

/**
 * Update database to specific tag (full control with labels)
 * @param tag Target tag to update to
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 */
public void update(String tag, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

Update SQL Generation

Generate SQL for update operations without executing them:

/**
 * Generate update SQL
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void updateSql(Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate SQL for limited number of changesets
 * @param count Number of changesets to generate SQL for
 * @param contexts Contexts for filtering changesets  
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void updateCountSql(int count, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate SQL for update to tag
 * @param tag Target tag to generate SQL for
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering  
 * @param writer Writer for SQL output
 */
public void updateToTagSql(String tag, Contexts contexts, LabelExpression labelExpression, Writer writer) throws LiquibaseException

Update with SQL Output (Deprecated Methods)

The following update methods with Writer output are deprecated but still available:

/**
 * Update database with SQL output (deprecated)
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 * @deprecated Use updateSql instead
 */
@Deprecated
public void update(String contexts, Writer output) throws LiquibaseException

/**
 * Update database with SQL output (deprecated)
 * @param contexts Contexts for filtering changesets
 * @param output Writer for SQL output
 * @deprecated Use updateSql instead
 */
@Deprecated
public void update(Contexts contexts, Writer output) throws LiquibaseException

/**
 * Update database with SQL output (deprecated)
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 * @deprecated Use updateSql instead
 */
@Deprecated
public void update(Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Update database with SQL output and control (deprecated)
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 * @param checkLiquibaseTables Whether to check Liquibase tracking tables
 * @deprecated Use updateSql instead
 */
@Deprecated
public void update(Contexts contexts, LabelExpression labelExpression, Writer output, boolean checkLiquibaseTables) throws LiquibaseException

/**
 * Update limited changesets with SQL output
 * @param changesToApply Number of changesets to apply
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void update(int changesToApply, String contexts, Writer output) throws LiquibaseException

/**
 * Update limited changesets with SQL output (full control)
 * @param changesToApply Number of changesets to apply
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void update(int changesToApply, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Update to tag with SQL output
 * @param tag Target tag to update to
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void update(String tag, String contexts, Writer output) throws LiquibaseException

/**
 * Update to tag with SQL output (full control)
 * @param tag Target tag to update to  
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void update(String tag, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

Rollback Operations

Rollback by Count

Rollback a specific number of changesets:

/**
 * Rollback specified number of changesets
 * @param changesToRollback Number of changesets to rollback
 * @param contexts Comma-separated list of contexts
 */
public void rollback(int changesToRollback, String contexts) throws LiquibaseException

/**
 * Rollback with contexts and labels
 * @param changesToRollback Number of changesets to rollback
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void rollback(int changesToRollback, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Rollback with custom rollback script
 * @param changesToRollback Number of changesets to rollback
 * @param rollbackScript Custom rollback script
 * @param contexts Comma-separated list of contexts
 */
public void rollback(int changesToRollback, String rollbackScript, String contexts) throws LiquibaseException

/**
 * Rollback with custom rollback script (full control)
 * @param changesToRollback Number of changesets to rollback
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void rollback(int changesToRollback, String rollbackScript, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

Rollback by Count with SQL Output

Generate SQL for rollback operations by count:

/**
 * Generate rollback SQL by count
 * @param changesToRollback Number of changesets to rollback
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void rollback(int changesToRollback, String contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL by count with contexts
 * @param changesToRollback Number of changesets to rollback
 * @param contexts Contexts for filtering
 * @param output Writer for SQL output
 */
public void rollback(int changesToRollback, Contexts contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL by count (full control)
 * @param changesToRollback Number of changesets to rollback
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void rollback(int changesToRollback, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL by count with custom script
 * @param changesToRollback Number of changesets to rollback
 * @param rollbackScript Custom rollback script
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void rollback(int changesToRollback, String rollbackScript, String contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL by count with custom script (contexts)
 * @param changesToRollback Number of changesets to rollback
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 * @param output Writer for SQL output
 */
public void rollback(int changesToRollback, String rollbackScript, Contexts contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL by count with custom script (full control)
 * @param changesToRollback Number of changesets to rollback
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void rollback(int changesToRollback, String rollbackScript, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

Rollback by Tag

Rollback to a specific tag:

/**
 * Rollback to specific tag
 * @param tagToRollBackTo Target tag name
 * @param contexts Comma-separated list of contexts
 */
public void rollback(String tagToRollBackTo, String contexts) throws LiquibaseException

/**
 * Rollback to tag with contexts
 * @param tagToRollBackTo Target tag name
 * @param contexts Contexts for filtering
 */
public void rollback(String tagToRollBackTo, Contexts contexts) throws LiquibaseException

/**
 * Rollback to tag with full control
 * @param tagToRollBackTo Target tag name
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering  
 */
public void rollback(String tagToRollBackTo, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Rollback to tag with custom rollback script
 * @param tagToRollBackTo Target tag name
 * @param rollbackScript Custom rollback script
 * @param contexts Comma-separated list of contexts
 */
public void rollback(String tagToRollBackTo, String rollbackScript, String contexts) throws LiquibaseException

/**
 * Rollback to tag with custom rollback script (contexts)
 * @param tagToRollBackTo Target tag name
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 */
public void rollback(String tagToRollBackTo, String rollbackScript, Contexts contexts) throws LiquibaseException

/**
 * Rollback to tag with custom rollback script (full control)
 * @param tagToRollBackTo Target tag name
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void rollback(String tagToRollBackTo, String rollbackScript, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

Rollback by Tag with SQL Output

Generate SQL for rollback operations by tag:

/**
 * Generate rollback SQL to tag
 * @param tagToRollBackTo Target tag name
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void rollback(String tagToRollBackTo, String contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL to tag with contexts
 * @param tagToRollBackTo Target tag name
 * @param contexts Contexts for filtering
 * @param output Writer for SQL output
 */
public void rollback(String tagToRollBackTo, Contexts contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL to tag (full control)
 * @param tagToRollBackTo Target tag name
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void rollback(String tagToRollBackTo, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL to tag with custom script
 * @param tagToRollBackTo Target tag name
 * @param rollbackScript Custom rollback script
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void rollback(String tagToRollBackTo, String rollbackScript, String contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL to tag with custom script (contexts)
 * @param tagToRollBackTo Target tag name
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 * @param output Writer for SQL output
 */
public void rollback(String tagToRollBackTo, String rollbackScript, Contexts contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL to tag with custom script (full control)
 * @param tagToRollBackTo Target tag name
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void rollback(String tagToRollBackTo, String rollbackScript, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

Rollback by Date

Rollback to a specific point in time:

/**
 * Rollback to specific date
 * @param dateToRollBackTo Target date
 * @param contexts Comma-separated list of contexts
 */
public void rollback(Date dateToRollBackTo, String contexts) throws LiquibaseException

/**
 * Rollback to date with full control  
 * @param dateToRollBackTo Target date
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void rollback(Date dateToRollBackTo, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Rollback to date with custom rollback script
 * @param dateToRollBackTo Target date
 * @param rollbackScript Custom rollback script
 * @param contexts Comma-separated list of contexts
 */
public void rollback(Date dateToRollBackTo, String rollbackScript, String contexts) throws LiquibaseException

/**
 * Rollback to date with custom rollback script (full control)
 * @param dateToRollBackTo Target date
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void rollback(Date dateToRollBackTo, String rollbackScript, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

Rollback by Date with SQL Output

Generate SQL for rollback operations by date:

/**
 * Generate rollback SQL to date
 * @param dateToRollBackTo Target date
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void rollback(Date dateToRollBackTo, String contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL to date with custom script
 * @param dateToRollBackTo Target date
 * @param rollbackScript Custom rollback script
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void rollback(Date dateToRollBackTo, String rollbackScript, String contexts, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL to date (full control)
 * @param dateToRollBackTo Target date
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void rollback(Date dateToRollBackTo, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate rollback SQL to date with custom script (full control)
 * @param dateToRollBackTo Target date
 * @param rollbackScript Custom rollback script
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void rollback(Date dateToRollBackTo, String rollbackScript, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

Future Rollback SQL Generation

Generate rollback SQL for pending changesets (useful for planning rollback strategies):

/**
 * Generate future rollback SQL for all pending changesets
 * @param output Writer for SQL output
 */
public void futureRollbackSQL(Writer output) throws LiquibaseException

/**
 * Generate future rollback SQL with context filtering
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void futureRollbackSQL(String contexts, Writer output) throws LiquibaseException

/**
 * Generate future rollback SQL with table checking control
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 * @param checkLiquibaseTables Whether to check Liquibase tracking tables
 */
public void futureRollbackSQL(String contexts, Writer output, boolean checkLiquibaseTables) throws LiquibaseException

/**
 * Generate future rollback SQL for limited number of changesets
 * @param count Number of changesets to generate rollback SQL for
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void futureRollbackSQL(Integer count, String contexts, Writer output) throws LiquibaseException

/**
 * Generate future rollback SQL (full control)
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void futureRollbackSQL(Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate future rollback SQL for limited changesets with table checking
 * @param count Number of changesets to generate rollback SQL for
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 * @param checkLiquibaseTables Whether to check Liquibase tracking tables
 */
public void futureRollbackSQL(Integer count, String contexts, Writer output, boolean checkLiquibaseTables) throws LiquibaseException

/**
 * Generate future rollback SQL for limited changesets (full control)
 * @param count Number of changesets to generate rollback SQL for
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void futureRollbackSQL(Integer count, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate future rollback SQL for limited changesets (full control with table checking)
 * @param count Number of changesets to generate rollback SQL for
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 * @param checkLiquibaseTables Whether to check Liquibase tracking tables
 */
public void futureRollbackSQL(Integer count, Contexts contexts, LabelExpression labelExpression, Writer output, boolean checkLiquibaseTables) throws LiquibaseException

/**
 * Generate future rollback SQL to specific tag
 * @param tag Target tag to generate rollback SQL for
 * @param contexts Contexts for filtering changesets
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void futureRollbackSQL(String tag, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

Database Management Operations

Schema Operations

Drop database objects and manage schema:

/**
 * Drop all database objects tracked by Liquibase
 */
public void dropAll() throws DatabaseException

/**
 * Drop all database objects with history control
 * @param dropDbclhistory Whether to drop database changelog history table
 */
public void dropAll(Boolean dropDbclhistory) throws DatabaseException

/**
 * Drop all objects in specific schemas
 * @param schemas Target schemas to drop objects from
 */
public void dropAll(CatalogAndSchema... schemas) throws DatabaseException

/**
 * Drop all objects in specific schemas with history control
 * @param dropDbclhistory Whether to drop database changelog history table
 * @param schemas Target schemas to drop objects from
 */
public void dropAll(Boolean dropDbclhistory, CatalogAndSchema... schemas) throws DatabaseException

Tagging Operations

Manage database tags for rollback points:

/**
 * Tag the current database state
 * @param tagString Tag name to create
 */
public void tag(String tagString) throws LiquibaseException

/**
 * Check if a tag exists in the database
 * @param tagString Tag name to check
 * @return true if tag exists
 */
public boolean tagExists(String tagString) throws LiquibaseException

Checksum Operations

Manage changeset checksums for validation:

/**
 * Clear all checksums for recalculation
 */
public void clearCheckSums() throws LiquibaseException

/**
 * Calculate checksum for specific changeset by identifier
 * @param changeSetIdentifier Changeset identifier string
 * @return Calculated checksum
 */
public CheckSum calculateCheckSum(String changeSetIdentifier) throws LiquibaseException

/**
 * Calculate checksum for specific changeset
 * @param changeSetPath Changeset file path
 * @param changeSetId Changeset ID
 * @param changeSetAuthor Changeset author
 * @return Calculated checksum
 */
public CheckSum calculateCheckSum(String changeSetPath, String changeSetId, String changeSetAuthor) throws LiquibaseException

Status and Reporting Operations

Changeset Status

Query changeset execution status:

/**
 * Get list of unrun changesets (deprecated)
 * @param contexts Contexts for filtering
 * @return List of unrun changesets  
 * @deprecated Use listUnrunChangeSets(Contexts, LabelExpression) instead
 */
@Deprecated
public List<ChangeSet> listUnrunChangeSets(Contexts contexts) throws LiquibaseException

/**
 * Get list of unrun changesets
 * @param contexts Contexts for filtering
 * @param labels Label expression for filtering
 * @return List of unrun changesets
 */
public List<ChangeSet> listUnrunChangeSets(Contexts contexts, LabelExpression labels) throws LiquibaseException

/**
 * Get list of unrun changesets with table checking control
 * @param contexts Contexts for filtering
 * @param labels Label expression for filtering
 * @param checkLiquibaseTables Whether to check Liquibase tracking tables
 * @return List of unrun changesets
 */
public List<ChangeSet> listUnrunChangeSets(Contexts contexts, LabelExpression labels, boolean checkLiquibaseTables) throws LiquibaseException

/**
 * Get detailed status of all changesets (deprecated)
 * @param contexts Contexts for filtering
 * @return List of changeset statuses
 * @deprecated Use getChangeSetStatuses(Contexts, LabelExpression) instead
 */
@Deprecated
public List<ChangeSetStatus> getChangeSetStatuses(Contexts contexts) throws LiquibaseException

/**
 * Get detailed status of all changesets  
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @return List of changeset statuses
 */
public List<ChangeSetStatus> getChangeSetStatuses(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Get detailed status of all changesets with table checking control
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param checkLiquibaseTables Whether to check Liquibase tracking tables
 * @return List of changeset statuses
 */
public List<ChangeSetStatus> getChangeSetStatuses(Contexts contexts, LabelExpression labelExpression, boolean checkLiquibaseTables) throws LiquibaseException

/**
 * Get unexpected changesets (run but not in changelog)
 * @param contexts Comma-separated list of contexts
 * @return Collection of unexpected changesets  
 */
public Collection<RanChangeSet> listUnexpectedChangeSets(String contexts) throws LiquibaseException

/**
 * Get unexpected changesets with full control
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @return Collection of unexpected changesets
 */
public Collection<RanChangeSet> listUnexpectedChangeSets(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

Status Reporting

Generate status reports:

/**
 * Generate status report with contexts (string)
 * @param verbose Include verbose information
 * @param contexts Comma-separated list of contexts
 * @param out Writer for output
 */
public void reportStatus(boolean verbose, String contexts, Writer out) throws LiquibaseException

/**
 * Generate status report with contexts object
 * @param verbose Include verbose information
 * @param contexts Contexts for filtering
 * @param out Writer for output
 */
public void reportStatus(boolean verbose, Contexts contexts, Writer out) throws LiquibaseException

/**
 * Generate status report (full control)
 * @param verbose Include verbose information
 * @param contexts Contexts for filtering
 * @param labels Label expression for filtering  
 * @param out Writer for output
 */
public void reportStatus(boolean verbose, Contexts contexts, LabelExpression labels, Writer out) throws LiquibaseException

/**
 * Report unexpected changesets with contexts (string)
 * @param verbose Include verbose information
 * @param contexts Comma-separated list of contexts
 * @param out Writer for output
 */
public void reportUnexpectedChangeSets(boolean verbose, String contexts, Writer out) throws LiquibaseException

/**
 * Report unexpected changesets (full control)
 * @param verbose Include verbose information
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param out Writer for output
 */
public void reportUnexpectedChangeSets(boolean verbose, Contexts contexts, LabelExpression labelExpression, Writer out) throws LiquibaseException

Lock Management

Manage database locks:

/**
 * List current database locks
 * @return Array of current locks
 */
public DatabaseChangeLogLock[] listLocks() throws LiquibaseException

/**
 * Report current locks to output stream
 * @param out Output stream for lock report
 */
public void reportLocks(PrintStream out) throws LiquibaseException

/**
 * Force release all database locks
 */
public void forceReleaseLocks() throws LiquibaseException

Synchronization Operations

Changelog Synchronization

Synchronize changelog state with database:

/**
 * Mark changelog changesets as run without executing them
 * @param contexts Comma-separated list of contexts
 */
public void changeLogSync(String contexts) throws LiquibaseException

/**
 * Mark changelog changesets as run with contexts object (deprecated)
 * @param contexts Contexts for filtering
 * @deprecated Use changeLogSync(Contexts, LabelExpression) instead
 */
@Deprecated
public void changeLogSync(Contexts contexts) throws LiquibaseException

/**
 * Mark changelog changesets as run (full control)
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void changeLogSync(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Sync changelog to specific tag with contexts (string)
 * @param tag Target tag to sync to
 * @param contexts Comma-separated list of contexts
 */
public void changeLogSync(String tag, String contexts) throws LiquibaseException

/**
 * Sync changelog to specific tag (full control)
 * @param tag Target tag to sync to
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void changeLogSync(String tag, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Mark next changeset as run without executing it
 * @param contexts Comma-separated list of contexts  
 */
public void markNextChangeSetRan(String contexts) throws LiquibaseException

/**
 * Mark next changeset as run (full control)
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void markNextChangeSetRan(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

Synchronization with SQL Output

Generate SQL for synchronization operations:

/**
 * Generate sync SQL with contexts (string)
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void changeLogSync(String contexts, Writer output) throws LiquibaseException

/**
 * Generate sync SQL (full control)
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void changeLogSync(Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate sync to tag SQL with contexts (string)
 * @param tag Target tag to sync to
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void changeLogSync(String tag, String contexts, Writer output) throws LiquibaseException

/**
 * Generate sync to tag SQL (full control)
 * @param tag Target tag to sync to
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void changeLogSync(String tag, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

/**
 * Generate mark next changeset SQL with contexts (string)
 * @param contexts Comma-separated list of contexts
 * @param output Writer for SQL output
 */
public void markNextChangeSetRan(String contexts, Writer output) throws LiquibaseException

/**
 * Generate mark next changeset SQL (full control)
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param output Writer for SQL output
 */
public void markNextChangeSetRan(Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException

Validation and Documentation

Validation

Validate changelog files and database state:

/**
 * Validate changelog files and database consistency
 */
public void validate() throws LiquibaseException

Documentation Generation

Generate database documentation:

/**
 * Generate database documentation
 * @param outputDirectory Directory for generated documentation
 */
public void generateDocumentation(String outputDirectory) throws LiquibaseException

/**
 * Generate database documentation with contexts
 * @param outputDirectory Directory for generated documentation
 * @param contexts Comma-separated list of contexts
 */
public void generateDocumentation(String outputDirectory, String contexts) throws LiquibaseException

/**
 * Generate database documentation with contexts and schemas
 * @param outputDirectory Directory for generated documentation
 * @param contexts Comma-separated list of contexts
 * @param schemaList Specific schemas to document
 */
public void generateDocumentation(String outputDirectory, String contexts, CatalogAndSchema... schemaList) throws LiquibaseException

/**
 * Generate database documentation (full control)
 * @param outputDirectory Directory for generated documentation
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 * @param schemaList Specific schemas to document
 */
public void generateDocumentation(String outputDirectory, Contexts contexts, LabelExpression labelExpression, CatalogAndSchema... schemaList) throws LiquibaseException

Testing and Advanced Operations

Testing Methods

Methods for testing update and rollback operations:

/**
 * Test update and rollback operations
 * @param contexts Comma-separated list of contexts
 */
public void updateTestingRollback(String contexts) throws LiquibaseException

/**
 * Test update and rollback operations (full control)
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void updateTestingRollback(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Test update to tag and rollback operations
 * @param tag Target tag to test update to
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void updateTestingRollback(String tag, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

Advanced Database Management

Additional database state and management operations:

/**
 * Check and update Liquibase tracking tables
 * @param updateExistingNullChecksums Whether to update existing null checksums
 * @param databaseChangeLog Database changelog object
 * @param contexts Contexts for filtering
 * @param labelExpression Label expression for filtering
 */
public void checkLiquibaseTables(boolean updateExistingNullChecksums, DatabaseChangeLog databaseChangeLog, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException

/**
 * Check if it's safe to run update operations
 * @return true if safe to run update
 */
public boolean isSafeToRunUpdate() throws DatabaseException

Configuration and Lifecycle

Configuration and resource management methods:

/**
 * Set changelog parameter value
 * @param key Parameter key
 * @param value Parameter value
 */
public void setChangeLogParameter(String key, Object value)

/**
 * Close Liquibase instance and release resources (AutoCloseable)
 */
public void close() throws LiquibaseException

/**
 * Output header message (deprecated)
 * @param message Header message to output
 * @deprecated This method is deprecated
 */
@Deprecated
public void outputHeader(String message) throws DatabaseException

Resource Access

Property Access

Get Liquibase instance properties:

/**
 * Get associated database instance
 * @return Database instance
 */
public Database getDatabase()

/**
 * Get changelog file path
 * @return Changelog file path
 */
public String getChangeLogFile()

/**
 * Get resource accessor
 * @return Resource accessor instance
 */
public ResourceAccessor getResourceAccessor()

/**
 * Get changelog parameters
 * @return Changelog parameters instance  
 */
public ChangeLogParameters getChangeLogParameters()

/**
 * Get logger instance
 * @return Logger instance
 */
public Logger getLog()

/**
 * Get database changelog object
 * @return Database changelog object
 * @throws LiquibaseException if changelog cannot be loaded
 */
public DatabaseChangeLog getDatabaseChangeLog() throws LiquibaseException

/**
 * Get default change execution listener
 * @return Default change execution listener
 */
public DefaultChangeExecListener getDefaultChangeExecListener()

Comparison and Change Generation

Schema Comparison

Compare database schemas and generate difference reports:

/**
 * Compare two database schemas
 * @param referenceDatabase Reference database to compare against
 * @param targetDatabase Target database to compare
 * @param compareControl Control object specifying what to compare
 * @return Diff result containing differences
 */
public DiffResult diff(Database referenceDatabase, Database targetDatabase, CompareControl compareControl) throws LiquibaseException

Change Generation

Generate changelog from database structure:

/**
 * Generate changelog from database schema
 * @param catalogAndSchema Schema to generate changelog for
 * @param changeLogWriter Diff to changelog writer
 * @param outputStream Output stream for generated changelog
 * @param snapshotTypes Database object types to include
 */
public void generateChangeLog(CatalogAndSchema catalogAndSchema, DiffToChangeLog changeLogWriter, PrintStream outputStream, Class<? extends DatabaseObject>... snapshotTypes) throws DatabaseException, CommandExecutionException

/**
 * Generate changelog from database schema with custom serializer
 * @param catalogAndSchema Schema to generate changelog for
 * @param changeLogWriter Diff to changelog writer
 * @param outputStream Output stream for generated changelog
 * @param changeLogSerializer Custom changelog serializer
 * @param snapshotTypes Database object types to include
 */
public void generateChangeLog(CatalogAndSchema catalogAndSchema, DiffToChangeLog changeLogWriter, PrintStream outputStream, ChangeLogSerializer changeLogSerializer, Class<? extends DatabaseObject>... snapshotTypes) throws DatabaseException, CommandExecutionException

Example Usage

Complete Update Example

import liquibase.Liquibase;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.Contexts;
import liquibase.LabelExpression;

// Setup database connection
Connection connection = DriverManager.getConnection(
    "jdbc:postgresql://localhost:5432/mydb", "user", "password"
);
DatabaseConnection databaseConnection = new JdbcConnection(connection);
Database database = DatabaseFactory.getInstance()
    .findCorrectDatabaseImplementation(databaseConnection);

// Create Liquibase instance
Liquibase liquibase = new Liquibase(
    "db/changelog/db.changelog-master.xml",
    new ClassLoaderResourceAccessor(),
    database
);

try {
    // Execute update with contexts and labels
    liquibase.update(
        new Contexts("dev", "test"), 
        new LabelExpression("feature-1")
    );
    
    // Tag current state
    liquibase.tag("release-1.0");
    
    // Validate state
    liquibase.validate();
    
} finally {
    liquibase.close();
}

Status and Rollback Example

// Check status
List<ChangeSet> unrunChangeSets = liquibase.listUnrunChangeSets(
    new Contexts("prod"), 
    new LabelExpression()
);

System.out.println("Unrun changesets: " + unrunChangeSets.size());

// Rollback if needed
if (needsRollback) {
    liquibase.rollback("release-1.0", "prod");
}

// Generate rollback SQL for review
StringWriter sqlOutput = new StringWriter();
liquibase.rollbackToTagSql(
    "release-1.0", 
    new Contexts("prod"), 
    new LabelExpression(), 
    sqlOutput
);
System.out.println("Rollback SQL:\n" + sqlOutput.toString());

Install with Tessl CLI

npx tessl i tessl/maven-org-liquibase--liquibase-core

docs

changelog.md

command-framework.md

configuration.md

database-operations.md

database-support.md

diff-comparison.md

exceptions.md

index.md

tile.json