Hi all,
I am evaluating liquibase and I am just getting involved with it, however I have an existential question: Is liquibase oriented to be used on the build system? Or can it be integrated in my application, which could read the changes set and to apply to my current data base when necessary? The other question that I have is, what is the purpose of the integration with Spring?, the idea is to integrate Spring to the build process? or to apply the data base changes from the application that uses a data base?
I hope you can help me to clarify these questions.
Thanks in advance.
-ovu
It is designed to be used in both. You can run liquibase via ant, maven, or command line which are targeted at build processes and there are also the Servlet Listener and Spring integration which are targeted at execution time. Most people probably use both systems.
For example, my applications generally use the Ant target to update the test databases and check the upgrade process on every build. That way any tests you have that run against the database will run against the upgraded schema. You will also find any liquibase script errors right away as well. We also use the Ant target as part of the developer build process as they are creating new database changes.
We also have the servlet listener set up as well, so when we deploy a new version of our web-based application, the database is automatically upgraded as part of application startup.
Nathan
Thanks Nathan for your answer. What I am trying to do is to integrate liquibase with my application, which does not use Spring. Is there any way to do that? Is that anywhere a sample?
Thanks in advance,
-ovu
Originally posted by: ovu
What I am trying to do is to integrate liquibase with my application, which does not use Spring. Is there any way to do that?
I had to do something similar recently (a single central dashboard for managing updates for all DEV/UAT/Production environments within a company) and ended up calling the CLI’s static main(String) method (didn’t had the time to go over the source code and figure out how to do it “properly” – another choice could be to take the ant target code and pull the ant-specific legs off). Anyway, re-using main() in my code gives me access to all the power of liquibase CLI, with only minor (in my case) integration issues, so I went for that.
I don’t think liquibase has a “customer-ready” API at the moment; I would have to read through quite a bit of the sources to hook into it.
What I’d love though would be an API with the functionality of liquibase Ant tasks, but without any dependencies on Ant environment. Essentially, a liquibase service bean, an object that I could instantiate in my code, or through spring, and then just call it’s methods as I need them (select a changelog file, get details for all updates, do update, generate SQL, and so on. Does it sound useful to anyone else? (I’m thinking of finding some time to write the required patches, but I won’t bother if it’s too niche to ever be accepted into the official codebase). Actually, would it be possible to implement something like that (an API extension) through the new 2.0 plugin interface? Probably not, would need to be a patch…
Also, what just came to my mind… wouldn’t it be nice if that hypothethical liquibase API could do resource lookups through some sort of a locator interface (put resource path in, get resource stream/File object out)? One could then easily write a custom locator and make it fetch changelogs directly from VCS, or through http, or whatever… Or virtually change the working directory by prefixing something to all resource paths on the fly, making it possible to work around any problems with relative paths in changesets. That would put icing on the cake for me… (maybe it’s already possible, haven’t really looked at liquibase internals yet).
There is an API designed to be used by 3rd parties to integrate liquibase as needed into their application. The upcoming 2.0 release is being refactored to make it much more extensible as well. Most of the documentation is currently at http://liquibase.jira.com/wiki/display/CONTRIB/LiquiBase+Extensions+Portal under “resources” on the right. Calling liquibase programatically is easy (from http://liquibase.jira.com/wiki/display/CONTRIB/Liquibase+Facade):
Liquibase liquibase = new Liquibase(changelog, new ClassLoaderResourceAccessor(), DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection));
liquibase.update();
Liquibase does currently use a resource locator pattern for looking up changelog files, classes, etc., but that has yet to be documented. It should be within the next few weeks.
If you run into any problems with the API or find areas where the documenation can be improved, be sure to let us know.
Nathan