Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • You want to simulate identity fields in Oracle, so you create a Change to create a sequence and set an insert trigger using a single tag in your changelog.

How to Create

To create a new Change class, implement the liquibase.change.Change interface directly, or extend the liquibase.change.AbstractChange_ class.

...

When extending AbstractChange, the only methods you need to implement are:

Code Block

public SqlStatement[] generateStatements(Database database)

in which you return an array of SqlStatements that should be executed, and

Code Block

public String getConfirmationMessage()

...

The following methods are optional if extending AbstractChange, but depending on what you are implementing you may wish to override them. If you are implementing liquibase.change.Change directly, they must be implemented.

Code Block

public ChangeMetaData getChangeMetaData();

Returns a ChangeMetaData object describing the command name (used by change log parsers), description, and priority of this Change implementation. AbstractChange returns values passed into its constructor.

Code Block

public void init() throws SetupException

Called by LiquiBase after all properties are set. AbstractChange implements this as a no-op.

Code Block

boolean supports(Database database);

Does the Change support the passed database? AbstractChange checks the supports method on all the SqlStatements returned by generateStatements().

Code Block

public ValidationErrors validate(Database database);

Are the properties set on the Change valid? AbstractChange checks the validate method on all the SqlStatements returned by generateStatements().

Code Block

public Set<DatabaseObject> getAffectedDatabaseObjects(Database database);

What database objects are affected by this change. Used for dbdoc command. AbstractChange checks the validate method on all the SqlStatements returned by generateStatements().

Code Block

public CheckSum generateCheckSum();

Generates a checksum for the change. AbstractChange uses liquibase.parser.string.StringChangeLogSerializer to generate a standarized representation of the change, and creates an MD5Sum hash.

Code Block

public boolean supportsRollback(Database database);

Does the Change support rollback? AbstractChange returns true if the AbstractChange-specific createInverses() method returns a non-null value.

Code Block

public SqlStatement[] generateRollbackStatements(Database database) throws UnsupportedChangeException, RollbackImpossibleException;

...

AbstractChange convenience methods to override

Code Block

protected Change[] createInverses()

...