@yamilurbina

Web and mobile developer, soon-to-be entrepreneur and startup maker.


Facebook
LinkedIn
Twitter

Web and mobile developer, soon-to-be entrepreneur and startup maker.


Facebook
LinkedIn
Twitter
  • ask me anything
  • rss
  • archive
  • Deploying a Sinatra + DataMapper + SQLite app to Heroku

    Recently I followed the excellent Nettuts’ session on Singing with Sinatra, and I learned a lot about Rack-only apps.

    I pushed the app to Heroku and all I was getting was “Application Error”. I found out that Heroku only uses PostgreSQL as database, so SQLite will not work at all. This is what you should do:

    a) Make sure you have a .gems file on the top folder with all the gems you need:

    sinatra
    data_mapper
    rack-flash
    sinatra-redirect-with-flash
    builder
    dm-postgres-adapter


    Did you notice the dm-postgres-adapter at the end?. That gem is ABSOLUTE NECESSARY if you coded your app using SQLite and DataMapper and you want to push it to Heroku. I repeat. ABSOLUTE NECESSARY.

    b) We also need a configure.ru file at the top folder:

    require 'your_sinatra_app_file_name'
    run Sinatra::Application
    


    c) On your Sinatra file (the one that has all the code) we need to tell DataMapper which database to use:

    # Setting up the database
    DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/mydatabase.db")
    


    The part ENV['DATABASE_URL'] is used by Heroku to assign a database to our app. If we are developing locally, we just use mydatabase.db, which is SQLite. Got it?

    d) Finally, we push the DB to Heroku:

    heroku db:push sqlite://mydatabase.db #assuming you are on your app directory
    


    Our SQLite database will be translated to a PostgreSQL database automatically. No hassle!

    Just push it (the app, I mean) and there you go. It will work. You are a hero.

    You can follow me on twitter @yamilurbina or Google plus for any questions you may have. It’s ok, I’m a cool lad.

    • April 22, 2011 (10:32 pm)
    • 11 notes
    • #deploy
    • #git
    • #sinatra
    • #datamapper
    • #sqlite
    • #postgresql
    • #push
    • #gem
    • #ruby
    • #rack
    1. emileeyou89 likes this
    2. yeseniauio09 likes this
    3. vhbsouza reblogged this from yamilurbina
    4. yamilurbina posted this
© 2009–2013 @yamilurbina