Search code examples
ruby-on-railsjrubyrails-migrationswarbler

Execute db:migrate and db:setup rake tasks inside a controller using jruby and warble


I'm creating an app that must allow the non-programmer end user to install the application by himself.

I already handled the ruby env + web server + database installation part. Now I have to be able to setup the database for the app. I'm thinking about running rake db:setup inside a InstallationController (which will be only accessible during the installation process).

Is it possible? How can I do that?

I'm planning to use Warble and JRuby, so I won't be able to do it by using the command-line inside my app.


Solution

  • As long as the database exists (or creates on use like sqlite3) you can throw an initializer in your app to run the migrations pretty easily.

    ActiveRecord::Migrator.migrate(Rails.root.join('db','migrate'))