Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

model migrations

  • Loading branch information...
commit 737cb04f0dbd99c0c079b5023e82aea930bb26cb 1 parent 270b27f
Paul Chavard tchak authored

Showing 4 changed files with 65 additions and 0 deletions. Show diff stats Hide diff stats

  1. +1 0  Gemfile
  2. +2 0  Gemfile.lock
  3. +8 0 httpcron.rb
  4. +54 0 lib/models.rb
1  Gemfile
@@ -5,3 +5,4 @@ gem 'slim', '~> 0.9'
5 5 gem 'sequel', '~> 3.25'
6 6 gem 'sinatra-sequel', '~> 0.9'
7 7 gem 'rufus-scheduler', '~> 2.0'
  8 +gem 'sqlite3'
2  Gemfile.lock
@@ -14,6 +14,7 @@ GEM
14 14 slim (0.9.4)
15 15 temple (~> 0.3.0)
16 16 tilt (~> 1.2)
  17 + sqlite3 (1.3.3)
17 18 temple (0.3.2)
18 19 tilt (1.3.2)
19 20 tzinfo (0.3.29)
@@ -27,3 +28,4 @@ DEPENDENCIES
27 28 sinatra (~> 1.2)
28 29 sinatra-sequel (~> 0.9)
29 30 slim (~> 0.9)
  31 + sqlite3
8 httpcron.rb
@@ -3,6 +3,7 @@
3 3
4 4 require 'json'
5 5 require 'logger'
  6 +require 'sqlite3'
6 7 #require 'tzinfo'
7 8
8 9 require 'sinatra/base'
@@ -28,4 +29,11 @@ class HTTPCron < Sinatra::Base
28 29 slim :index
29 30 end
30 31
  32 + get '/tasks.json' do
  33 + tasks = Task.all.to_json
  34 + halt 200, {'Content-Type' => 'application/json'}, tasks
  35 + end
  36 +
31 37 end
  38 +
  39 +require_relative 'lib/models'
54 lib/models.rb
... ... @@ -0,0 +1,54 @@
  1 +
  2 +migration 'create table tasks/users/executions' do
  3 +
  4 + database.create_table :users do
  5 + primary_key :id, :type => Integer, :null => false
  6 +
  7 + String :username, :size => 250, :null => true, :index => true
  8 + end
  9 +
  10 + database.create_table :tasks do
  11 + primary_key :id, :type => Integer, :null => false
  12 + foreign_key :user_id, :users
  13 +
  14 + String :name, :size => 250, :null => true, :index => true
  15 + String :url, :size => 255, :null => false
  16 + String :cron, :size => 50, :null => false
  17 + boolean :enabled, :null => false, :index => true, :default => true
  18 + DateTime :created_at, :null => false
  19 + DateTime :updated_at, :null => false
  20 + DateTime :next_execution, :null => false
  21 + end
  22 +
  23 + database.create_table :executions do
  24 + primary_key :id, :type => Integer, :null => false
  25 + foreign_key :task_id, :tasks
  26 +
  27 + Integer :status, :null => false
  28 + Integer :duration, :null => false
  29 + DateTime :run_at, :null => false
  30 + String :response, :size => 5000, :null => false
  31 + end
  32 +end
  33 +
  34 +class Task < Sequel::Model
  35 + many_to_one :user
  36 + one_to_many :executions
  37 +
  38 + def validate
  39 + validates_presence :name
  40 + validates_presence :url
  41 + validates_presence :cron
  42 + validates_presence :enabled
  43 + validates_presence :next_execution
  44 + end
  45 +
  46 +end
  47 +
  48 +class User < Sequel::Model
  49 + one_to_many :tasks
  50 +end
  51 +
  52 +class Execution < Sequel::Model
  53 + many_to_one :task
  54 +end

0 comments on commit 737cb04

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