No shell access - how to run migrations on production db?

Hey,

I have no shell access to the production server, but would still like
to use migrations to maintain the database.

Is it possible to run migrations from Ruby code itself (ie, without
using 'rake')?

If so, I'll be able to run migrations by hitting a 'migration'
controller, with the URL specifying the version number somehow. (Yes,
I appreciate the potential problems with having a publicly-accessible
migration URL)

Thanks in advance for any ideas...

  Matthew

I have no shell access to the production server, but would still like
to use migrations to maintain the database.

How are you currently deploying the application? If using Capistrano,
it's as simple as:
cap deploy:migrate

ftp. (It's highly technical! :wink:

M

ftp. (It's highly technical! :wink:

Ouch. I haven't had that problem since my asp days in the 90s.

From the AWD... book:

"All of the migration methods described so far in this chapter are
also available
as methods on Active Record connection objects and so are accessible within
the models, views, and controllers of a Rails application. "

So you could have a controller (with restricted access!) to accept an
http request that calls a model / method to run the migration.

You could even pass a version number as a parameter.

That sounds like a plan - thanks for you ideas Toby.

M

Yes, if you look at vendor/rails/railties/lib/tasks/databases.rake,
you'll see what rake db:migrate does. It's just one line:

  ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ?
ENV["VERSION"].to_i : nil)

If you always want to migrate up to latest version, just use:

  ActiveRecord::Migrator.migrate("db/migrate/")

ActiveRecord::Migrator is undocumented (there's too much undocumented
stuff in Rails; I use http://caboo.se/doc/ to hunt for this kind of
thing).

The rake task also dumps the schema, but you wouldn't need to worry about that.

Thank-you Bob - that's exactly what I was looking for :slight_smile:

  Matthew

For anyone with the same problem, I blogged a quick-and-dirty solution
here:
http://insignificant.org/2007/12/03/rails-migration-without-ssh/