Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Table for treasures! Migrations! Oh my!

  • Loading branch information...
commit 51fe6c33b85462d94c73261967544892d19d9beb 1 parent 383504f
@peat authored
View
22 server/Rakefile
@@ -0,0 +1,22 @@
+require 'active_record'
+require 'uri'
+
+task :default => :migrate
+
+desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
+task :migrate => :environment do
+ ActiveRecord::Migrator.migrate('migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
+end
+
+task :environment do
+ db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb')
+
+ ActiveRecord::Base.establish_connection(
+ :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
+ :host => db.host,
+ :username => db.user,
+ :password => db.password,
+ :database => db.path[1..-1],
+ :encoding => 'utf8'
+ )
+end
View
13 server/lib/mhd_app.rb
@@ -1,9 +1,22 @@
require 'json'
+require 'activerecord'
+require 'uri'
+
class MHDApp < Sinatra::Application
def ensure_connections
# connect to DB here
+ db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb')
+
+ ActiveRecord::Base.establish_connection(
+ :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
+ :host => db.host,
+ :username => db.user,
+ :password => db.password,
+ :database => db.path[1..-1],
+ :encoding => 'utf8'
+ )
end
before do
View
11 server/migrations/201202111853_create_treasures.rb
@@ -0,0 +1,11 @@
+class CreateTreasures < ActiveRecord::Migration
+ def self.up
+ create_table :treasures do
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :treasures
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.