Permalink
Browse files

Base app to register hits to db

  • Loading branch information...
0 parents commit 2fc585b355cf1397ade47ae14ff88e994bd9a46f @rwdaigle committed Jun 24, 2011
Showing with 120 additions and 0 deletions.
  1. +2 −0 .env
  2. +1 −0 .gitignore
  3. +1 −0 .rvmrc
  4. +11 −0 Gemfile
  5. +46 −0 Gemfile.lock
  6. +1 −0 Procfile
  7. +1 −0 README
  8. +12 −0 Rakefile
  9. +8 −0 config.rb
  10. +19 −0 config.ru
  11. +5 −0 config/database.yml
  12. +13 −0 db/migrate/001_init.rb
2 .env
@@ -0,0 +1,2 @@
+LANG=en_US.UTF-8
+RACK_ENV=development
1 .gitignore
@@ -0,0 +1 @@
+db/*.sql*
1 .rvmrc
@@ -0,0 +1 @@
+rvm use ruby-1.9.2@demo.db-replication --create
11 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 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 Procfile
@@ -0,0 +1 @@
+web: bundle exec thin start -p $PORT -e $RACK_ENV
1 README
@@ -0,0 +1 @@
+
12 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 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 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 config/database.yml
@@ -0,0 +1,5 @@
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
13 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.