Question

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.

Was it helpful?

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

OTHER TIPS

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`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top