Not published anywhere, but I'm building a site to manage Magic the
Gathering decks in heroku, using PG. I used Sequel models as my ORM.
In my local machine I use SQLite. The application is just a test to
learn a bit more about Sinatra and Heroku. I'm not sure I'll even
continue developing it, although I have learnt a lot, so that's good.
Basically the setup stuff is like this (I haven't used bundler, so if
the problems are because of that this is not going to be very useful,
though):
require './magic_decks'
run MagicDecks
models.rb (required from the sinatra application):
require 'sequel'
# Use Heroku's environment variable or a sqlite db when locally
DB = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite://decks.sqlite')
require 'logger'
DB.logger = Logger.new($stdout)
class Card < Sequel::Model(:mtg_database)
[...] # all the models stuff
I have this rakefile (can't remember where I copied it from) to run
the migrations both locally and in heroku. It uses the same trick
about heroku's env variable or the sqlite url to my local file:
namespace :db do
require 'sequel'
Sequel.extension :migration
task :migrate do
puts "task migrate"
m = Sequel::Migrator
db = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite://decks.sqlite')
dir = "migrations"
target = ENV['TARGET'] ? ENV['TARGET'].to_i : nil
current = ENV['CURRENT'] ? ENV['CURRENT'].to_i : nil
puts "target: #{target}, current: #{current}"
m.run(db, dir, :target => target, :current => current)
puts "migrator finished running"
end
end
I have a migrations folder with the migrations. For example this is
the start of the first one (001_initial.rb):
Sequel.migration do
up do
create_table(:mtg_database) do
Integer :gatherer_id, :primary_key => true
[...]
The sinatra file just requires models and stuff and has usual routes and so on:
# encoding: UTF-8
require 'sinatra/base'
require 'open-uri'
require 'nokogiri'
require 'uri'
require 'cgi'
require_relative 'models'
require_relative 'gatherer_searcher'
class MagicDecks < Sinatra::Base
[...] # the rest of the class
I also have a .gems file with the gems I use:
sinatra
nokogiri
sequel
sqlite3
And I think that's all. From the sinatra application I can use the
Sequel models just fine.
Hope this helps,
Jesus.
2012/1/14 Jesús Gabriel y Galán <jgabrie...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "sinatrarb" group.
> To post to this group, send email to sina...@googlegroups.com.
> To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.
>