After working in a rails environment for the past year I found it terribly difficult to go back to traditional database deployment / upgrade practices.

Migrations are a beautiful way to properly version, co-ordinate and apply the changes you need to your various database environments.  I never knew of a way to do this in a non-rails environment, until now. Step in AutoPatch.

Some alternatives to AutoPatch exist such as migrate4j and Liquibase. Each with their own flavor of how to tackle the problem. AutoPatch was the winner for me as you don’t have to write your migrations in some custom DSL (xml in the case of Liquibase, or java for migrate4j). Our existing .sql scripts worked just fine!

Our shop is currently using Capistrano for deployments. Blending Autopatch with Capistrano was relatively straightforward. Below are two sample tasks that can be added to facilitate AutoPatch’s cmd line info and migrate calls.

desc "Display database migration levels."
task :dbinfo do
cmdAPClasspath = "#{deployDir}/applications/database/lib/oracle/ojdbc14_g.jar" \
+ ":#{deployDir}/dist/prepare/database" \
+ ":#{deployDir}/lib/java/tk-autopatch-1.2-b-cvs.jar" \
+ ":#{deployDir}/lib/java/log4j-1.2.8.jar" \
+ ":#{deployDir}/lib/java/commons-logging-1.0.3.jar" \
+ ":#{deployDir}/lib/java/commons-collections-3.2.1.jar" \
+ ":#{deployDir}/lib/java/commons-lang-2.2.jar" \
+ ":#{deployDir}/lib/java/tk-util-1.1.2.jar"
cmdAPPatchInfo = "java -cp #{cmdAPClasspath} " \
+ "com.tacitknowledge.util.migration.jdbc.MigrationInformation
#{systemName}"
system(cmdAPPatchInfo)
end

desc "Apply database migrations."
task :dbmigrate do
cmdAPClasspath = "#{deployDir}/applications/database/lib/oracle/ojdbc14_g.jar" \
+ ":#{deployDir}/dist/prepare/database" \
+ ":#{deployDir}/lib/java/tk-autopatch-1.2-b-cvs.jar" \
+ ":#{deployDir}/lib/java/log4j-1.2.8.jar" \
+ ":#{deployDir}/lib/java/commons-logging-1.0.3.jar" \
+ ":#{deployDir}/lib/java/commons-collections-3.2.1.jar" \
+ ":#{deployDir}/lib/java/commons-lang-2.2.jar" \
+ ":#{deployDir}/lib/java/tk-util-1.1.2.jar"
cmdAPPatchInfo = "java -cp #{cmdAPClasspath} " \
+ "com.tacitknowledge.util.migration.jdbc.StandaloneMigrationLauncher #{systemName}"
system(cmdAPPatchInfo)
end

Post to Twitter Tweet This Post