Skip to content

Commit

Permalink
Base app to register hits to db
Browse files Browse the repository at this point in the history
  • Loading branch information
rwdaigle committed Jun 24, 2011
0 parents commit 2fc585b
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env
@@ -0,0 +1,2 @@
LANG=en_US.UTF-8
RACK_ENV=development
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
db/*.sql*
1 change: 1 addition & 0 deletions .rvmrc
@@ -0,0 +1 @@
rvm use ruby-1.9.2@demo.db-replication --create
11 changes: 11 additions & 0 deletions Gemfile
@@ -0,0 +1,11 @@
source "http://rubygems.org"

gem 'thin'
gem 'sinatra'
gem 'activerecord'

group :development, :test do
gem 'foreman'
gem 'sqlite3'
gem 'rake'
end
46 changes: 46 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,46 @@
GEM
remote: http://rubygems.org/
specs:
activemodel (3.0.9)
activesupport (= 3.0.9)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.9)
activemodel (= 3.0.9)
activesupport (= 3.0.9)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activesupport (3.0.9)
arel (2.0.10)
builder (2.1.2)
daemons (1.1.3)
eventmachine (0.12.10)
foreman (0.18.0)
term-ansicolor (~> 1.0.5)
thor (>= 0.13.6)
i18n (0.5.0)
rack (1.2.2)
rake (0.9.2)
sinatra (1.2.6)
rack (~> 1.1)
tilt (< 2.0, >= 1.2.2)
sqlite3 (1.3.3)
term-ansicolor (1.0.5)
thin (1.2.11)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.14.6)
tilt (1.3)
tzinfo (0.3.28)

PLATFORMS
ruby

DEPENDENCIES
activerecord
foreman
rake
sinatra
sqlite3
thin
1 change: 1 addition & 0 deletions Procfile
@@ -0,0 +1 @@
web: bundle exec thin start -p $PORT -e $RACK_ENV
1 change: 1 addition & 0 deletions README
@@ -0,0 +1 @@

12 changes: 12 additions & 0 deletions Rakefile
@@ -0,0 +1,12 @@
namespace :db do

task :environment do
load 'config.rb'
end

desc "Migrate the database"
task(:migrate => :environment) do
ActiveRecord::Migrator.migrate("db/migrate")
end
end

8 changes: 8 additions & 0 deletions config.rb
@@ -0,0 +1,8 @@
require 'active_record'
require 'logger'

dbconfig = YAML.load(File.read('config/database.yml'))
ActiveRecord::Base.establish_connection dbconfig[ENV['RACK_ENV'] || 'development']

ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.verbose = true
19 changes: 19 additions & 0 deletions config.ru
@@ -0,0 +1,19 @@
require "rubygems"
require "bundler"
Bundler.setup

require 'sinatra/base'
load 'config.rb'

class Hit < ActiveRecord::Base
end

class DbReplicationDemoApp < Sinatra::Base

get "/" do
Hit.create(:ip => request.ip)
"Hi #{request.ip}"
end
end

run DbReplicationDemoApp
5 changes: 5 additions & 0 deletions config/database.yml
@@ -0,0 +1,5 @@
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
13 changes: 13 additions & 0 deletions db/migrate/001_init.rb
@@ -0,0 +1,13 @@
class Init < ActiveRecord::Migration
def self.up
create_table "hits" do |t|
t.string "ip"
t.datetime "created_at"
end
end

def self.down
drop_table "hits"
end
end

0 comments on commit 2fc585b

Please sign in to comment.