Permalink
Browse files

Database migrations

  • Loading branch information...
1 parent 8653f10 commit daba80f8474d82785b6c34987110072957193e90 @dce dce committed Oct 22, 2009
Showing with 508 additions and 27 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 Rakefile
  3. +9 −18 app/models/site.rb
  4. +17 −0 config/database.example.yml
  5. +18 −0 db/migrate/001_create_sites.rb
  6. +25 −0 db/schema.rb
  7. +7 −5 init.rb
  8. +427 −0 tasks/databases.rake
  9. +0 −4 test/test_helper.rb
View
@@ -9,3 +9,5 @@ tmp/*
tmp/**/*
config/settings.yml
config/deploy.rb
+config/database.yml
+db/*.sqlite3
View
@@ -10,6 +10,9 @@ end
task :environment do
$:.push(File.dirname(__FILE__))
require 'init'
+
+ ActiveRecord::Base.logger = Logger.new('log/database.log')
+ RAILS_ROOT = File.dirname(__FILE__)
end
Dir['tasks/**/*.rake'].each do |rakefile|
View
@@ -1,7 +1,7 @@
require 'uri'
require 'fileutils'
-class Site < Ohm::Model
+class Site < ActiveRecord::Base
module Regex
include URI::REGEXP::PATTERN
# A general email regular expression. It allows top level domains (TLD) to be from 2 - 4 in length, any
@@ -31,15 +31,6 @@ def save_with_monit_callback
private :save_with_monit_callback
alias_method_chain :save, :monit_callback
- attribute :name
- attribute :url
- attribute :match_text
- attribute :threshold
- attribute :email
- list :status_record
-
- index :url
-
def validate
assert_present :name
assert_present :url
@@ -61,13 +52,13 @@ def latest_status
end
private
- def create_monit_check
- @template = MonitCheck.new(self)
- File.open(root_path('monitrc', RACK_ENV, "#{self.id}.monitrc"), 'w') do |file|
- file << @template.render
- end
- FileUtils.chmod 0700, root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
- system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload"
- end
+ def create_monit_check
+ @template = MonitCheck.new(self)
+ File.open(root_path('monitrc', RACK_ENV, "#{self.id}.monitrc"), 'w') do |file|
+ file << @template.render
+ end
+ FileUtils.chmod 0700, root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
+ system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload"
+ end
end
@@ -0,0 +1,17 @@
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
@@ -0,0 +1,18 @@
+class CreateSites < ActiveRecord::Migration
+ def self.up
+ create_table :sites do |t|
+ t.string :name
+ t.string :url
+ t.text :match_text
+ t.integer :threshold
+ t.string :email
+ t.string :status_record
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :sites
+ end
+end
View
@@ -0,0 +1,25 @@
+# This file is auto-generated from the current state of the database. Instead of editing this file,
+# please use the migrations feature of Active Record to incrementally modify your database, and
+# then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your database schema. If you need
+# to create the application database on another system, you should be using db:schema:load, not running
+# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 1) do
+
+ create_table "sites", :force => true do |t|
+ t.string "name"
+ t.string "url"
+ t.text "match_text"
+ t.integer "threshold"
+ t.string "email"
+ t.string "status_record"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
View
@@ -10,24 +10,26 @@
require "monk/glue"
require 'active_support'
+require 'active_record'
require 'mustache/sinatra'
-require 'ohm'
class Main < Monk::Glue
set :app_file, __FILE__
use Rack::Session::Cookie
register Mustache::Sinatra
set :views, root_path('app', 'templates')
set :mustaches, root_path('app', 'views')
-
+
configure do
- Ohm.connect
-
+ # Set up ActiveRecord
+ @db_config = YAML.load(File.open('config/database.yml'))
+ ActiveRecord::Base.establish_connection(@db_config[Main.environment.to_s])
+
# Load all application files.
Dir[root_path("app/**/*.rb")].each do |file|
require file
end
- end
+ end
end
Main.run! if Main.run?
Oops, something went wrong. Retry.

0 comments on commit daba80f

Please sign in to comment.