Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Base app to register hits to db

  • Loading branch information...
commit 2fc585b355cf1397ade47ae14ff88e994bd9a46f 0 parents
Ryan Daigle authored
2  .env
... ... @@ -0,0 +1,2 @@
  1 +LANG=en_US.UTF-8
  2 +RACK_ENV=development
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +db/*.sql*
1  .rvmrc
... ... @@ -0,0 +1 @@
  1 +rvm use ruby-1.9.2@demo.db-replication --create
11 Gemfile
... ... @@ -0,0 +1,11 @@
  1 +source "http://rubygems.org"
  2 +
  3 +gem 'thin'
  4 +gem 'sinatra'
  5 +gem 'activerecord'
  6 +
  7 +group :development, :test do
  8 + gem 'foreman'
  9 + gem 'sqlite3'
  10 + gem 'rake'
  11 +end
46 Gemfile.lock
... ... @@ -0,0 +1,46 @@
  1 +GEM
  2 + remote: http://rubygems.org/
  3 + specs:
  4 + activemodel (3.0.9)
  5 + activesupport (= 3.0.9)
  6 + builder (~> 2.1.2)
  7 + i18n (~> 0.5.0)
  8 + activerecord (3.0.9)
  9 + activemodel (= 3.0.9)
  10 + activesupport (= 3.0.9)
  11 + arel (~> 2.0.10)
  12 + tzinfo (~> 0.3.23)
  13 + activesupport (3.0.9)
  14 + arel (2.0.10)
  15 + builder (2.1.2)
  16 + daemons (1.1.3)
  17 + eventmachine (0.12.10)
  18 + foreman (0.18.0)
  19 + term-ansicolor (~> 1.0.5)
  20 + thor (>= 0.13.6)
  21 + i18n (0.5.0)
  22 + rack (1.2.2)
  23 + rake (0.9.2)
  24 + sinatra (1.2.6)
  25 + rack (~> 1.1)
  26 + tilt (< 2.0, >= 1.2.2)
  27 + sqlite3 (1.3.3)
  28 + term-ansicolor (1.0.5)
  29 + thin (1.2.11)
  30 + daemons (>= 1.0.9)
  31 + eventmachine (>= 0.12.6)
  32 + rack (>= 1.0.0)
  33 + thor (0.14.6)
  34 + tilt (1.3)
  35 + tzinfo (0.3.28)
  36 +
  37 +PLATFORMS
  38 + ruby
  39 +
  40 +DEPENDENCIES
  41 + activerecord
  42 + foreman
  43 + rake
  44 + sinatra
  45 + sqlite3
  46 + thin
1  Procfile
... ... @@ -0,0 +1 @@
  1 +web: bundle exec thin start -p $PORT -e $RACK_ENV
1  README
... ... @@ -0,0 +1 @@
  1 +
12 Rakefile
... ... @@ -0,0 +1,12 @@
  1 +namespace :db do
  2 +
  3 + task :environment do
  4 + load 'config.rb'
  5 + end
  6 +
  7 + desc "Migrate the database"
  8 + task(:migrate => :environment) do
  9 + ActiveRecord::Migrator.migrate("db/migrate")
  10 + end
  11 +end
  12 +
8 config.rb
... ... @@ -0,0 +1,8 @@
  1 +require 'active_record'
  2 +require 'logger'
  3 +
  4 +dbconfig = YAML.load(File.read('config/database.yml'))
  5 +ActiveRecord::Base.establish_connection dbconfig[ENV['RACK_ENV'] || 'development']
  6 +
  7 +ActiveRecord::Base.logger = Logger.new(STDOUT)
  8 +ActiveRecord::Migration.verbose = true
19 config.ru
... ... @@ -0,0 +1,19 @@
  1 +require "rubygems"
  2 +require "bundler"
  3 +Bundler.setup
  4 +
  5 +require 'sinatra/base'
  6 +load 'config.rb'
  7 +
  8 +class Hit < ActiveRecord::Base
  9 +end
  10 +
  11 +class DbReplicationDemoApp < Sinatra::Base
  12 +
  13 + get "/" do
  14 + Hit.create(:ip => request.ip)
  15 + "Hi #{request.ip}"
  16 + end
  17 +end
  18 +
  19 +run DbReplicationDemoApp
5 config/database.yml
... ... @@ -0,0 +1,5 @@
  1 +development:
  2 + adapter: sqlite3
  3 + database: db/development.sqlite3
  4 + pool: 5
  5 + timeout: 5000
13 db/migrate/001_init.rb
... ... @@ -0,0 +1,13 @@
  1 +class Init < ActiveRecord::Migration
  2 + def self.up
  3 + create_table "hits" do |t|
  4 + t.string "ip"
  5 + t.datetime "created_at"
  6 + end
  7 + end
  8 +
  9 + def self.down
  10 + drop_table "hits"
  11 + end
  12 +end
  13 +

0 comments on commit 2fc585b

Please sign in to comment.
Something went wrong with that request. Please try again.