Migrations with Warfile deployment?

We want to give a versioned WAR to customers for deployment on their
internal environment, and are wondering how to handle migrations. It
seems like a chicken-and-egg problem - you can’t fire up a new war
until you run the migrations, but you can’t run migrations which are
zipped up inside the WAR.

How do others handle this? Give them a separate executable file/jar
(with a version matching the WAR) to run manually? Something else?

Thanks,
– Chad


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Chad,
For a production application I would NEVER use this for schema changes
and
such, too much can go wrong. I’m used to running DB schema changes by
hand.

However, we do have a demo app we give out which will auto run a
migration,
since we’re not talking about mission critical code. Here are the steps
you
will take:

  1. In your web.xml.erb, define a listener. Here’s an example:
jruby.ext.StartupScriptLauncher
  1. Compile this class and make sure the JAR or .class file is available
    to
    your Rails application:

http://pastie.org/635371

(I believe my friend Jerry shameless stole this code from Nick S.,
so
credit to him)

  1. Now add a script in script/startup (we load this script in line 32).
    This
    script needs to load the Rails env. Here’s the script we use:

http://pastie.org/635373

The magic here is:

ActiveRecord::Migrator.migrate(“#{RAILS_ROOT}/db/migrate/”, nil)

Note that when you do things this way, you run the risk of migrations
not
running right, etc. It may not be worth it.

Ikai

Chad:

This is a little long in the tooth now, but I cooked up this

for a project. Basically it applys the migrations when you deploy.

HTH

On Nov 5, 2009, at 5:06 PM, Benjamin Christenson wrote:

it is being run in “configuration mode” and allows an administrator
Thanks,

wrote:
– Chad


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Michael Hagedorn
Silverchair Solutions - Agile Web Develoment
Houston, Tx [email protected]

does that help ?

On Thu, Nov 5, 2009 at 6:12 PM, Michael Hagedorn
[email protected] wrote:

A little late in responding, but we are working on a solution to a similar

Michael Hagedorn
Silverchair Solutions - Agile Web Develoment
Houston, Tx [email protected]
http://www.silverchairsolutions.com


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Chad,

A little late in responding, but we are working on a solution to a
similar
problem. We are working with a local code-hacker to build out a
strategy,
and the initial PoC looks good. The general strategy we are taking is
to
deploy our application pre-configured with a sqlite3 database.

For installation, a customer simply deploys the war file to unpack it.
Then, when they connect to the application, it identifies that it is
being
run in “configuration mode” and allows an administrator to configure the
database connection. This writes the configuration to database.yml and
executes ActiveRecord::Base.establish_connection. The administrator
then
has an option to execute migrations.

For upgrades, we provide a “configuration backup” that basically copies
out
the existing database.yml. The customer can then redeploy the war file,
and
load the backup to reconfigure the database.yml.

Thanks,
Ben Christenson
Developer/Analyst

Kinetic Data, Inc.
“Building a Better Service Experience”

651.556.0937 I www.kineticdata.com http://www.kineticdata.com