The idea behind the extensibility in Liquibase 2.0 is to allow just what you are looking for: to provide custom implementations of change classes without the changelog knowing about it at all.
A couple other doc links: http://liquibase.jira.com/wiki/display/CONTRIB/Overview and http://liquibase.jira.com/wiki/display/CONTRIB/Contributing
The general idea is that you can create custom classes that either extend from the standard class, or a completely different class that implements the Change interface. Liquibase looks for classes in liquibase.ext subpackages for classes that implement the given interfaces. If you want to use a different package, you can add a “LiquiBase-Package:” line in your META-INF folder
When liquibase uses your extension classes depends on what they are. For the Change classes, if the parser looks for the Change implementation(s) that return the given tag name as the getChangeMetaData().getName() method (normally set by passing the tag name into the AbstractChange superclass constructor). If there is more than one Change classes that return the given tag name, it will pick the one that has the highest getChangeMetaData().getPriority() value (normally set by passing priority to the AbstractChange superclass constructor).
A simple example would be:
public class SampleChange extends AbstractChange {
public SampleChange() {
super("addForeignKeyConstraint", "Custom FK Constraint Change", 15);
}
public SqlStatement[] generateStatements(Database database) {
return new SqlStatement[]{
new CreateTableStatement(null, “samplechange”).addColumn(“id”, “int”).addColumn(“name”, “varchar(5)”)
};
}
}
which will make it so all tags will generate a CreateTableStatement instead.
I really need to get to the docs on this…
What can make it more complicated, is that there are a couple integration points that may make more sense to you. If you look at the core AddForeignKeyConstraintChange class, it return a AddForeignKeyConstraintStatement class. The *Statement classes are a package containing all the information needed to generate database-specific SQL, and different Change classes can return the same Statement classes. There is a SqlGenerator extension point where you can override the default SqlGenerator for the AddForeignKeyConstraintStatement instead of overriding the Change class. See http://liquibase.jira.com/wiki/display/CONTRIB/SqlGenerator. The pattern is the same as overriding Change classes, but is for the SqlGenerator interface.
Creating custom Change classes is good if you want to change the type of statements returned, but not the SQL generated by those statements. In your case, you want to modify the generated SQL, so you will want to extend the SqlGenerator classes.
Does that help?
Nathan