Class: SportDb::Play::CreateDb

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/sportdb/play/schema.rb

Instance Method Summary collapse

Instance Method Details

#downObject

Raises:

  • (ActiveRecord::IrreversibleMigration)


144
145
146
# File 'lib/sportdb/play/schema.rb', line 144

def down
  raise ActiveRecord::IrreversibleMigration
end

#upObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/sportdb/play/schema.rb', line 6

def up

## NB: assumes a table users already exists with a col key
##  lets add a check? why? why not?
    
change_table :games do |t|
  t.boolean    :locked,  null: false, default: false
end


#####################################
## new tables / create tables
####################################

create_table :pools do |t|
  t.references  :event,  :null => false
  t.string      :title,  :null => false
  t.references  :user,   :null => false  # owner/manager/admin of pool
  t.boolean     :public, :null => false, :default => true   # make all tips public (not private/secret)
  t.boolean     :locked, :null => false, :default => false
  t.string      :key   # import/export key
  t.timestamps
end

add_index :pools, :key,   :unique => true 
add_index :pools, :event_id
add_index :pools, :user_id


create_table :plays do |t|
  t.references :user, :null => false
  t.references :pool, :null => false
  t.references :team1   # winner (1st)
  t.references :team2   # runnerup (2nd)
  t.references :team3   # 2n runnerup (3nd)

  t.integer    :total_pts, :null => false, :default => 0   # cached total player points 
  t.integer    :total_pos, :null => false, :default => 0   # cached total ranking/position 

  t.timestamps
end

add_index :plays, [:user_id,:pool_id], :unique => true  # enforce only one play per user and pool
add_index :plays, :user_id
add_index :plays, :pool_id


create_table :tips do |t|
  t.references :user, :null => false
  t.references :pool, :null => false
  t.references :game, :null => false
  t.integer    :score1
  t.integer    :score2
  t.integer    :score1et    # verlaengerung (opt)  - extra time/e.t
  t.integer    :score2et  
  t.integer    :score1p    # elfmeter (opt)
  t.integer    :score2p
  t.integer    :winner90      # 1,2,0,nil  calculate on save
  t.integer    :winner        # 1,2,0,nil  calculate on save

  t.timestamps
end


add_index :tips, [:user_id,:pool_id,:game_id], :unique => true 
add_index :tips, :user_id
add_index :tips, :pool_id
add_index :tips, :game_id



create_table :points do |t|
  t.references :user,  :null => false
  t.references :pool,  :null => false
  t.references :round, :null => false
  
  t.integer    :round_pts, :null => false, :default => 0   # points for this round
  t.integer    :round_pos, :null => false, :default => 0   # ranking/position for this round

  t.integer    :total_pts, :null => false, :default => 0   # total points up to(*) this round (including)  (* rounds sorted by pos)
  t.integer    :total_pos, :null => false, :default => 0   # ranking/position for points up to this round

  t.integer    :diff_total_pos, :null => false, :default => 0
  
  t.timestamps
end

add_index :points, [:user_id,:pool_id,:round_id], :unique => true 



create_table :bonus_rounds do |t|
  t.references :pool,   :null => false
  t.string     :title,  :null => false
  t.integer    :pos,     :null => false
  t.timestamps
end

create_table :bonus_questions do |t|
  t.references :round,  :null => false
  t.string     :title,  :null => false
  t.integer    :pos,    :null => false
  t.timestamps
end
    
create_table :bonus_answers do |t|
  # to be done
  t.timestamps
end
    
create_table :bonus_tips do |t|
  t.references :user,     :null => false
  t.references :question, :null => false
  t.integer    :pts     , :null => false, :default => 0
  t.timestamps
end

create_table :bonus_points do |t|
  t.references :user,  :null => false
  t.references :pool,  :null => false  ## todo: check if we keep reference to pool (because round_id depends itself on pool)
  t.references :round, :null => false   # nb: is bonus_round_id
  
  t.integer    :round_pts, :null => false, :default => 0   # points for this round
  t.integer    :round_pos, :null => false, :default => 0   # ranking/position for this round

  t.integer    :total_pts, :null => false, :default => 0   # total points up to(*) this round (including)  (* rounds sorted by pos)
  t.integer    :total_pos, :null => false, :default => 0   # ranking/position for points up to this round

  t.integer    :diff_total_pos, :null => false, :default => 0
  
  t.timestamps
end

add_index :bonus_points, [:user_id,:pool_id,:round_id], :unique => true

end