razenha
razenha

Reputation: 7732

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.

Upvotes: 1

Views: 1393

Answers (2)

codatory
codatory

Reputation: 686

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'))

Upvotes: 4

Federico Builes
Federico Builes

Reputation: 5097

You won't be able to use the controller if the database is not properly set. If the setup has to be through a web interface you can include a small Sinatra application that takes care of the DB creation, migrations, etc. To do it you only have to shell out your commands (you can do it by backquoting the command):

puts "Migrating database..."
`rake db:migrate`

Upvotes: 3

Related Questions