Permalink
Browse files

model migrations

  • Loading branch information...
1 parent 270b27f commit 737cb04f0dbd99c0c079b5023e82aea930bb26cb @tchak tchak committed Jul 12, 2011
Showing with 65 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +8 −0 httpcron.rb
  4. +54 −0 lib/models.rb
View
@@ -5,3 +5,4 @@ gem 'slim', '~> 0.9'
gem 'sequel', '~> 3.25'
gem 'sinatra-sequel', '~> 0.9'
gem 'rufus-scheduler', '~> 2.0'
+gem 'sqlite3'
View
@@ -14,6 +14,7 @@ GEM
slim (0.9.4)
temple (~> 0.3.0)
tilt (~> 1.2)
+ sqlite3 (1.3.3)
temple (0.3.2)
tilt (1.3.2)
tzinfo (0.3.29)
@@ -27,3 +28,4 @@ DEPENDENCIES
sinatra (~> 1.2)
sinatra-sequel (~> 0.9)
slim (~> 0.9)
+ sqlite3
View
@@ -3,6 +3,7 @@
require 'json'
require 'logger'
+require 'sqlite3'
#require 'tzinfo'
require 'sinatra/base'
@@ -28,4 +29,11 @@ class HTTPCron < Sinatra::Base
slim :index
end
+ get '/tasks.json' do
+ tasks = Task.all.to_json
+ halt 200, {'Content-Type' => 'application/json'}, tasks
+ end
+
end
+
+require_relative 'lib/models'
View
@@ -0,0 +1,54 @@
+
+migration 'create table tasks/users/executions' do
+
+ database.create_table :users do
+ primary_key :id, :type => Integer, :null => false
+
+ String :username, :size => 250, :null => true, :index => true
+ end
+
+ database.create_table :tasks do
+ primary_key :id, :type => Integer, :null => false
+ foreign_key :user_id, :users
+
+ String :name, :size => 250, :null => true, :index => true
+ String :url, :size => 255, :null => false
+ String :cron, :size => 50, :null => false
+ boolean :enabled, :null => false, :index => true, :default => true
+ DateTime :created_at, :null => false
+ DateTime :updated_at, :null => false
+ DateTime :next_execution, :null => false
+ end
+
+ database.create_table :executions do
+ primary_key :id, :type => Integer, :null => false
+ foreign_key :task_id, :tasks
+
+ Integer :status, :null => false
+ Integer :duration, :null => false
+ DateTime :run_at, :null => false
+ String :response, :size => 5000, :null => false
+ end
+end
+
+class Task < Sequel::Model
+ many_to_one :user
+ one_to_many :executions
+
+ def validate
+ validates_presence :name
+ validates_presence :url
+ validates_presence :cron
+ validates_presence :enabled
+ validates_presence :next_execution
+ end
+
+end
+
+class User < Sequel::Model
+ one_to_many :tasks
+end
+
+class Execution < Sequel::Model
+ many_to_one :task
+end

0 comments on commit 737cb04

Please sign in to comment.