Deploying Sinatra (DataMapper, SQlite, Postgresql) Applications to Heroku
Recently deployed a simple Sinatra application using Datamapper on Heroku . I have been using Heroku for over a year and a sizeable fraction of another year.
I made use of the Sqlite database in my development environment and Postgresql in the production environment.
Creating an heroku application is usually a cinch once you have the heroku toolbelt installed on your system. Quick Link
Once you have the toolbelt installed and setup, and your application working well on the local server, all you need to do would be to check out the deployment methods for rack based applications Here.
Without a database, you should be good to go but once you have a database as part of your application, you would need to activate Heroku Postgres Addon .
You would then need to set the appropriate datamapper adapters to be used in your development and production envionments.
**Your main.rb file containing the require 'sinatra' line**
configure :development do
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/development.db")
end
configure :production do
DataMapper.setup(:default, ENV['HEROKU_POSTGRESQL_RED_URL'])
end
**Your Gemfile would need the following lines added**
group :production do
gem "pg"
gem "dm-postgres-adapter"
end
group :development, :test do
gem "sqlite3"
gem "dm-sqlite-adapter"
end
Once you do that, run the usual :
$git add .
$git commit -m "your message"
$git push heroku master
When it successfully pushes, you would then need to do an auto_migrate! as usual to create the appropriate tables and columns.
$heroku run console
The above command opens the irb console of your application production environment, here you would just need to :
$2.0.0-p0 :001>require './main.rb'
$2.0.0-p0 :002>DataMapper.auto_migrate!
Then you should be good to go!
P.S : This was written in a bit of a rush. Do let me know if you have any problems with deploying. :)
Written by Akapo Damilola Francis
Related protips
1 Response
This really helped. Heroku is simple when you know how to use it.