[Cosmo-dev] new migration framework
Randy Letness
randy at osafoundation.org
Mon Dec 11 08:47:10 PST 2006
In order to do a Derby migration, I pretty much had to write java code,
so I ended up writing a basic database migration framework that works
with both Derby and MySQL. I have checked this in under
cosmo/migration. Instructions on building and running are contained in
the README.txt.
The basics:
1. build using 'mvn package', which creates an all-in-one jar under
cosmo/migration/target
2. edit migration.properties file located in cosmo/migration to suit
your database (both Derby and MySQL examples are included)
3. run the executable jar file like: java -jar
target/cosmo-migration-jar-with-dependencies.jar migration.properties
or for verbose mode: java -jar
cosmo-migration-jar-with-dependencies.jar -v migration.properties
The nice thing about this framework is that it can be configured to
migrate any previous version of Cosmo (starting with 0.5) to the latest
version, by choosing what migrations to run (based on the version found
in the database) and running them in order. This will make implementing
migrations for future version of Cosmo simple. It can be as easy as
dropping in a sql script and configuring a spring bean, or if the
migration requires complex data manipulation, you can implement a
migrateData() method using JDBC. On my machine the JDBC based migration
against MySQL is faster than the sql script that uses cursors. That
could be because I'm not an expert in writing stored procedures and the
current script is highly inefficient.
So now that there are two ways of migrating a MySQL db, do we support
both? Do we need both? The difference is that the new migration
framework requires java to be run, but since Cosmo is a java program, I
don't see that as too big of a problem. Right now its not a big deal ,
but down the road when someone wants to migrate from 0.6 to 0.7, its
nice to only have to run a single command, instead of running a script
to migrate 0.6 to 0.6.1, then another for 0.6.1 to 0.6.2, and finally
from 0.6.2 to 0.7.0.
We can also hook this framework up to the DbListenter and do
auto-migrations on Cosmo startup if we wanted to.
-Randy
More information about the cosmo-dev
mailing list