How are custom refactoring Change types (e.g. modifySql) implemented?

Hi,


(I need this for Clj-Liquibase 0.2, which is now under development.)


How are the custom refactoring Change types implemented in code? For example, I can’t find any Change class that directly correlates to modifySql – however, I suspect it might have been implemented using liquibase.change.custom.CustomSqlChange, which leads me to wonder how is the original-SQL parameter passed for modification? It seems that modifySql operates on the immediately-preceding change in the changeset?


http://www.liquibase.org/manual/home

http://www.liquibase.org/manual/modify_sql


Do I need to take special care while including such change types in a changeset?


Regards,

Shantanu

There is actually a difference between CustomSqlChange and how modifySql works. They are also both different than how the extension system in 2.0 works. The goal of all three is to allow writers of the changelog to override built-in standard liquibase functionality if they need something more or something different.


CustomSqlChange was created first, and allows people to create a java class that implements the CustomSqlChange interface. They can add a tag to their changeset with a class attribute that lists the class that implements CustomSqlChange and the class is ran like it was any other liquibase change. The way it is actually implemented is a built-in CustomChangeWrapper class that calls out to the CustomSqlChange implementation.


ModifySql was then added for people who don’t want to (or cannot) create a custom class for the functionality they want. Instead, they can use the to define text replacements/changes to the generated SQL. This allows them to add an engine=“INNODB” clause to the end of a create table change, for example.


2.0 added the extension system which lets users take much fuller control of available changes and generated SQL, but custom and modifySql are still there for compatability. modifySql still makes sense as an option since it works well for non-java devs, but CustomSqlChange has been superseded by the extension system. You can use the modifyColumn extension as an example with clj-liquibase (http://liquibase.jira.com/wiki/display/CONTRIB/ModifyColumn+Change)


From an DatabaseChangeLog object population standpoint, you should be able to call ChangeFactory.getInstance().create(tagname) to get an instance of the Change class, whether it is a built-in class or an extension.


modifySql tags are converted to SqlVistor instances using SqlVisitorFactory.getInstance().create(tagName) and then added to the Change object by change.addSqlVisitor(visitor)


Nathan