Description:
created join tables for contests and users and problems
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r268:5fffb74cc182 - - 6 files changed: 42 inserted, 1 deleted
@@ -0,0 +1,12 | |||||
|
|
1 | + class CreateContestsUsersJoinTable < ActiveRecord::Migration | ||
|
|
2 | + def self.up | ||
|
|
3 | + create_table :contests_users, :id => false do |t| | ||
|
|
4 | + t.integer :contest_id | ||
|
|
5 | + t.integer :user_id | ||
|
|
6 | + end | ||
|
|
7 | + end | ||
|
|
8 | + | ||
|
|
9 | + def self.down | ||
|
|
10 | + drop_table :contests_users | ||
|
|
11 | + end | ||
|
|
12 | + end |
@@ -0,0 +1,12 | |||||
|
|
1 | + class CreateContestsProblemsJoinTable < ActiveRecord::Migration | ||
|
|
2 | + def self.up | ||
|
|
3 | + create_table :contests_problems, :id => false do |t| | ||
|
|
4 | + t.integer :contest_id | ||
|
|
5 | + t.integer :problem_id | ||
|
|
6 | + end | ||
|
|
7 | + end | ||
|
|
8 | + | ||
|
|
9 | + def self.down | ||
|
|
10 | + drop_table :contests_problems | ||
|
|
11 | + end | ||
|
|
12 | + end |
@@ -1,2 +1,6 | |||||
|
1 | class Contest < ActiveRecord::Base |
|
1 | class Contest < ActiveRecord::Base |
|
|
2 | + | ||
|
|
3 | + has_and_belongs_to_many :users | ||
|
|
4 | + has_and_belongs_to_many :problems | ||
|
|
5 | + | ||
|
2 | end |
|
6 | end |
@@ -1,27 +1,28 | |||||
|
1 | class Problem < ActiveRecord::Base |
|
1 | class Problem < ActiveRecord::Base |
|
2 |
|
2 | ||
|
3 | belongs_to :description |
|
3 | belongs_to :description |
|
|
4 | + has_and_belongs_to_many :contests | ||
|
4 | has_many :test_pairs, :dependent => :delete_all |
|
5 | has_many :test_pairs, :dependent => :delete_all |
|
5 |
|
6 | ||
|
6 | validates_presence_of :name |
|
7 | validates_presence_of :name |
|
7 | validates_format_of :name, :with => /^\w+$/ |
|
8 | validates_format_of :name, :with => /^\w+$/ |
|
8 | validates_presence_of :full_name |
|
9 | validates_presence_of :full_name |
|
9 |
|
10 | ||
|
10 | DEFAULT_TIME_LIMIT = 1 |
|
11 | DEFAULT_TIME_LIMIT = 1 |
|
11 | DEFAULT_MEMORY_LIMIT = 32 |
|
12 | DEFAULT_MEMORY_LIMIT = 32 |
|
12 |
|
13 | ||
|
13 | def self.find_available_problems |
|
14 | def self.find_available_problems |
|
14 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
15 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
15 | end |
|
16 | end |
|
16 |
|
17 | ||
|
17 | def self.create_from_import_form_params(params, old_problem=nil) |
|
18 | def self.create_from_import_form_params(params, old_problem=nil) |
|
18 | problem = old_problem || Problem.new |
|
19 | problem = old_problem || Problem.new |
|
19 | import_params = Problem.extract_params_and_check(params, problem) |
|
20 | import_params = Problem.extract_params_and_check(params, problem) |
|
20 |
|
21 | ||
|
21 | if not problem.valid? |
|
22 | if not problem.valid? |
|
22 | return problem, 'Error importing' |
|
23 | return problem, 'Error importing' |
|
23 | end |
|
24 | end |
|
24 |
|
25 | ||
|
25 | problem.full_score = 100 |
|
26 | problem.full_score = 100 |
|
26 | problem.date_added = Time.new |
|
27 | problem.date_added = Time.new |
|
27 | problem.test_allowed = true |
|
28 | problem.test_allowed = true |
@@ -1,47 +1,49 | |||||
|
1 | require 'digest/sha1' |
|
1 | require 'digest/sha1' |
|
2 |
|
2 | ||
|
3 | class User < ActiveRecord::Base |
|
3 | class User < ActiveRecord::Base |
|
4 |
|
4 | ||
|
5 | has_and_belongs_to_many :roles |
|
5 | has_and_belongs_to_many :roles |
|
6 |
|
6 | ||
|
7 | has_many :test_requests, :order => "submitted_at DESC" |
|
7 | has_many :test_requests, :order => "submitted_at DESC" |
|
8 |
|
8 | ||
|
9 | has_many :messages, |
|
9 | has_many :messages, |
|
10 | :class_name => "Message", |
|
10 | :class_name => "Message", |
|
11 | :foreign_key => "sender_id", |
|
11 | :foreign_key => "sender_id", |
|
12 | :order => 'created_at DESC' |
|
12 | :order => 'created_at DESC' |
|
13 |
|
13 | ||
|
14 | has_many :replied_messages, |
|
14 | has_many :replied_messages, |
|
15 | :class_name => "Message", |
|
15 | :class_name => "Message", |
|
16 | :foreign_key => "receiver_id", |
|
16 | :foreign_key => "receiver_id", |
|
17 | :order => 'created_at DESC' |
|
17 | :order => 'created_at DESC' |
|
18 |
|
18 | ||
|
19 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
19 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
20 |
|
20 | ||
|
21 | belongs_to :site |
|
21 | belongs_to :site |
|
22 | belongs_to :country |
|
22 | belongs_to :country |
|
23 |
|
23 | ||
|
|
24 | + has_and_belongs_to_many :contests | ||
|
|
25 | + | ||
|
24 | named_scope :activated_users, :conditions => {:activated => true} |
|
26 | named_scope :activated_users, :conditions => {:activated => true} |
|
25 |
|
27 | ||
|
26 | validates_presence_of :login |
|
28 | validates_presence_of :login |
|
27 | validates_uniqueness_of :login |
|
29 | validates_uniqueness_of :login |
|
28 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
30 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
29 | validates_length_of :login, :within => 3..30 |
|
31 | validates_length_of :login, :within => 3..30 |
|
30 |
|
32 | ||
|
31 | validates_presence_of :full_name |
|
33 | validates_presence_of :full_name |
|
32 | validates_length_of :full_name, :minimum => 1 |
|
34 | validates_length_of :full_name, :minimum => 1 |
|
33 |
|
35 | ||
|
34 | validates_presence_of :password, :if => :password_required? |
|
36 | validates_presence_of :password, :if => :password_required? |
|
35 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
37 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
36 | validates_confirmation_of :password, :if => :password_required? |
|
38 | validates_confirmation_of :password, :if => :password_required? |
|
37 |
|
39 | ||
|
38 | validates_format_of :email, |
|
40 | validates_format_of :email, |
|
39 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
41 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
40 | :if => :email_validation? |
|
42 | :if => :email_validation? |
|
41 | validate :uniqueness_of_email_from_activated_users, |
|
43 | validate :uniqueness_of_email_from_activated_users, |
|
42 | :if => :email_validation? |
|
44 | :if => :email_validation? |
|
43 | validate :enough_time_interval_between_same_email_registrations, |
|
45 | validate :enough_time_interval_between_same_email_registrations, |
|
44 | :if => :email_validation? |
|
46 | :if => :email_validation? |
|
45 |
|
47 | ||
|
46 | # these are for ytopc |
|
48 | # these are for ytopc |
|
47 | # disable for now |
|
49 | # disable for now |
@@ -1,72 +1,82 | |||||
|
1 | # This file is auto-generated from the current state of the database. Instead of editing this file, |
|
1 | # This file is auto-generated from the current state of the database. Instead of editing this file, |
|
2 | # please use the migrations feature of Active Record to incrementally modify your database, and |
|
2 | # please use the migrations feature of Active Record to incrementally modify your database, and |
|
3 | # then regenerate this schema definition. |
|
3 | # then regenerate this schema definition. |
|
4 | # |
|
4 | # |
|
5 | # Note that this schema.rb definition is the authoritative source for your database schema. If you need |
|
5 | # Note that this schema.rb definition is the authoritative source for your database schema. If you need |
|
6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
9 | # |
|
9 | # |
|
10 | # It's strongly recommended to check this file into your version control system. |
|
10 | # It's strongly recommended to check this file into your version control system. |
|
11 |
|
11 | ||
|
12 |
- ActiveRecord::Schema.define(:version => 201002161 |
|
12 | + ActiveRecord::Schema.define(:version => 20100216162940) do |
|
13 |
|
13 | ||
|
14 | create_table "announcements", :force => true do |t| |
|
14 | create_table "announcements", :force => true do |t| |
|
15 | t.string "author" |
|
15 | t.string "author" |
|
16 | t.text "body" |
|
16 | t.text "body" |
|
17 | t.boolean "published" |
|
17 | t.boolean "published" |
|
18 | t.datetime "created_at" |
|
18 | t.datetime "created_at" |
|
19 | t.datetime "updated_at" |
|
19 | t.datetime "updated_at" |
|
20 | t.boolean "frontpage", :default => false |
|
20 | t.boolean "frontpage", :default => false |
|
21 | t.boolean "contest_only", :default => false |
|
21 | t.boolean "contest_only", :default => false |
|
22 | t.string "title" |
|
22 | t.string "title" |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | create_table "codejom_statuses", :force => true do |t| |
|
25 | create_table "codejom_statuses", :force => true do |t| |
|
26 | t.integer "user_id" |
|
26 | t.integer "user_id" |
|
27 | t.boolean "alive" |
|
27 | t.boolean "alive" |
|
28 | t.integer "num_problems_passed" |
|
28 | t.integer "num_problems_passed" |
|
29 | t.datetime "created_at" |
|
29 | t.datetime "created_at" |
|
30 | t.datetime "updated_at" |
|
30 | t.datetime "updated_at" |
|
31 | end |
|
31 | end |
|
32 |
|
32 | ||
|
33 | create_table "configurations", :force => true do |t| |
|
33 | create_table "configurations", :force => true do |t| |
|
34 | t.string "key" |
|
34 | t.string "key" |
|
35 | t.string "value_type" |
|
35 | t.string "value_type" |
|
36 | t.string "value" |
|
36 | t.string "value" |
|
37 | t.datetime "created_at" |
|
37 | t.datetime "created_at" |
|
38 | t.datetime "updated_at" |
|
38 | t.datetime "updated_at" |
|
39 | t.text "description" |
|
39 | t.text "description" |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | create_table "contests", :force => true do |t| |
|
42 | create_table "contests", :force => true do |t| |
|
43 | t.string "title" |
|
43 | t.string "title" |
|
44 | t.boolean "enabled" |
|
44 | t.boolean "enabled" |
|
45 | t.datetime "created_at" |
|
45 | t.datetime "created_at" |
|
46 | t.datetime "updated_at" |
|
46 | t.datetime "updated_at" |
|
47 | end |
|
47 | end |
|
48 |
|
48 | ||
|
|
49 | + create_table "contests_problems", :id => false, :force => true do |t| | ||
|
|
50 | + t.integer "contest_id" | ||
|
|
51 | + t.integer "problem_id" | ||
|
|
52 | + end | ||
|
|
53 | + | ||
|
|
54 | + create_table "contests_users", :id => false, :force => true do |t| | ||
|
|
55 | + t.integer "contest_id" | ||
|
|
56 | + t.integer "user_id" | ||
|
|
57 | + end | ||
|
|
58 | + | ||
|
49 | create_table "countries", :force => true do |t| |
|
59 | create_table "countries", :force => true do |t| |
|
50 | t.string "name" |
|
60 | t.string "name" |
|
51 | t.datetime "created_at" |
|
61 | t.datetime "created_at" |
|
52 | t.datetime "updated_at" |
|
62 | t.datetime "updated_at" |
|
53 | end |
|
63 | end |
|
54 |
|
64 | ||
|
55 | create_table "descriptions", :force => true do |t| |
|
65 | create_table "descriptions", :force => true do |t| |
|
56 | t.text "body" |
|
66 | t.text "body" |
|
57 | t.boolean "markdowned" |
|
67 | t.boolean "markdowned" |
|
58 | t.datetime "created_at" |
|
68 | t.datetime "created_at" |
|
59 | t.datetime "updated_at" |
|
69 | t.datetime "updated_at" |
|
60 | end |
|
70 | end |
|
61 |
|
71 | ||
|
62 | create_table "grader_processes", :force => true do |t| |
|
72 | create_table "grader_processes", :force => true do |t| |
|
63 | t.string "host", :limit => 20 |
|
73 | t.string "host", :limit => 20 |
|
64 | t.integer "pid" |
|
74 | t.integer "pid" |
|
65 | t.string "mode" |
|
75 | t.string "mode" |
|
66 | t.boolean "active" |
|
76 | t.boolean "active" |
|
67 | t.datetime "created_at" |
|
77 | t.datetime "created_at" |
|
68 | t.datetime "updated_at" |
|
78 | t.datetime "updated_at" |
|
69 | t.integer "task_id" |
|
79 | t.integer "task_id" |
|
70 | t.string "task_type" |
|
80 | t.string "task_type" |
|
71 | t.boolean "terminated" |
|
81 | t.boolean "terminated" |
|
72 | end |
|
82 | end |
You need to be logged in to leave comments.
Login now