GarinDriver plus LiquiBase
Posted by Mark on June 27, 2009
|
GarinDriver is an JDBC driver and schema manager that I created to supports a schema deployment. The driver wraps your backend driver and provides a framework for SQL/DML script recording and playback to streamline distribution of changes across environments. The driver can also be configured to run with the enhanced schema manager or use the standard LiquiBase SchemaManager via an option in it’s JDBC URL. With both models, GarinDriver ensures that schema changes are automatically deployed BEFORE client code connects to the system. With the enhanced manager, the schema change stream is defined as a “stack” of numbered SQL and/or XML files. This model works well with mysqldump, Toad, SQLPlus, and similar tools. Tools like mysqldump are especially useful for creating a complete system script in one simple step. Subsequent scripts can also be written as general SQL standard files and/or use the full flexibility and power of the native dialect. The driver level DML recording feature provides an option to record DML statements you issue in your JDBC based tools and automatically add them to the schema stack. This option means that you can configure ANY schema tool that uses JDBC and automatically captured the numbered series of scripts to build your schema distribution table. In addition at any point you can place LiquiBase XML files in the stack to provide flexibility for vendor neutrality while also having an option for running the vendor specific scripts when and where they make the most sense. The combination of GarinDriver and LiquiBase provides a lot of power and flexibility for complex envirionments. For more information about GarinDriver please visit the main project site. http://code.google.com/p/garindriver/ We will be providing additional documentation in our wiki in the coming weeks. |
Jakob said
Hello Mark,
interesting approach. So your driver sits in between the actual app and the actual JDBC driver? Where does the Liquibase provider read its changelogs from? How does it know which migrations to apply?
I’m looking for a solution that transparently keeps the database schema up to date but I still have to find a solution that satisfies me.
Cheers,
Jakob
Mark said
Users specify the location of the change log and an optional liquibase context via parameters in the JDBC url:
jdbcUrl = "garin:s=tst/deploy1/changelog.xml,c=demo:jdbc:h2:mem:garinDB";If you want to run the default context you can omit the c= paramter:
jdbcUrl = "garin:s=tst/deploy1/changelog.xml:jdbc:h2:mem:garinDB";The paths in the example above are relative the the location where the JVM is running.
As you can see the “backend” driver is supplied at the end of jdbc URL.
If you are looking for a solution that “solution that transparently keeps the database schema up to date” and you are not currently using liquibase you should decide if database neutrality is important to you.
For me I find that I prefer the standard SQL change set model since all the create, alter, and data scripts are represented in native SQL for my chosen backend. Since it is rare for me to change RMDBS system mid project this model usually works well for me because I prefer SQL syntax over the XML version.
Also, for the ultimate in transparent implementation, I generally use the GarinDriver in record mode in my tools and in standard mode in the runtime. In record mode, any script that is not a simple select is recorded by the driver and added to the stack of sql files.
To use record mode setup your tools using the r=[folder] option:
url = "garin:r=/cygwin/home/Mark/wksp/VehicleCrashDataImporter/db:jdbc:postgresql://localhost:5432/nitsa"In the applications use the s=[folder] option:
url = "garin:s=/cygwin/home/Mark/wksp/VehicleCrashDataImporter/db:jdbc:postgresql://localhost:5432/nitsa"Paths can be absolute or relative but when using record mode absolute paths are useful since it is often hard to determine the current directory for tools (i.e. in eclipse the data tools run from the eclipse home directory so a relative path would be relative to the eclipse home).