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

**URL:** <https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487>\
**Category:** Rails\
**Created:** [November 28, 2007, 12:44pm UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487 "2007-11-28T12:44:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [November 28, 2007, 12:44pm UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487/1 "2007-11-28T12:44:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [November 28, 2007, 12:58pm UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487/2 "2007-11-28T12:58:33Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [November 28, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487/3 "2007-11-28T13:06:09Z")

</div>

Nov 28, 11:57 am, “toby privett” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 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?

ftp. (It’s highly technical! 😉

M

---

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [November 28, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487/4 "2007-11-28T14:58:19Z")

</div>

On Nov 28, 12:14 pm, “toby privett” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [November 28, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487/5 "2007-11-28T13:15:30Z")

</div>

> ftp. (It’s highly technical! 😉

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.

---

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [November 28, 2007, 3:38pm UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487/6 "2007-11-28T15:38:12Z")

</div>

On Nov 28, 2007 6:43 AM, Matthew F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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’)?

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/](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.

---

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [November 28, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487/7 "2007-11-28T15:44:39Z")

</div>

On Nov 28, 2:37 pm, “Bob S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yes, if you look at vendor/rails/railties/lib/tasks/databases.rake,  
> stuff in Rails; I usehttp://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 🙂

Matthew

---

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [December 4, 2007, 10:08am UTC](https://www.ruby-forum.com/t/no-shell-access-how-to-run-migrations-on-production-db/121487/8 "2007-12-04T10:08:03Z")

</div>

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