Class: BeerDb::CreateDb

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

Instance Method Summary collapse

Instance Method Details

#downObject

method up

Raises:

  • (ActiveRecord::IrreversibleMigration)


159
160
161
# File 'lib/beerdb/schema.rb', line 159

def down
  raise ActiveRecord::IrreversibleMigration
end

#upObject



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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/beerdb/schema.rb', line 8

def up

create_table :beers do |t|
  t.string  :key,   :null => false   # import/export key
  t.string  :title, :null => false
  t.string  :synonyms  # comma separated list of synonyms

  t.string  :web    # optional url link (e.g. )
  t.integer :since  # optional year (e.g. 1896)

  t.boolean  :bottle,  :null => false, :default => false # Flaschenbier
  t.boolean  :draft,   :null => false, :default => false # Fassbier
  ## todo: check seasonal is it proper english?
  t.boolean  :seasonal, :null => false, :default => false # all year or just eg. Festbier/Oktoberfest Special
  ## todo: add microbrew/brewpub flag?
  #### t.boolean  :brewpub, :null => false, :default => false
  
  ## add t.boolean :lite  flag ??
  t.decimal    :kcal    # kcal/100ml e.g. 45.0 kcal/100ml

  ## check: why decimal and not float? 
  t.decimal    :abv    # Alcohol by volume (abbreviated as ABV, abv, or alc/vol) e.g. 4.9 %
  t.decimal    :og     # malt extract (original gravity) in plato
  t.integer    :srm    # color in srm
  t.integer    :ibu    # bitterness in ibu

  ### fix/todo: add bitterness field

  # renamed - old field names
  ## t.decimal    :plato  # stammwuerze / gravity in plato scale (e.g. °P) e.g. 12.6°   - todo: use a different field name e.g. just p or gravity?
  ## t.integer    :color  # beer color in Standard Reference Method (SRM)

# see en.wikipedia.org/wiki/Plato_scale#Colour

# SRM/Lovibond  | Example  | Beer color  | EBC
# ---------------------------------------------------------------
# 2  | Pale lager, Witbier, Pilsener, Berliner Weisse  | #F8F753 | 4
# 3  | Maibock, Blonde Ale                             | #F6F513 | 6
# 4  | Weissbier                                       | #ECE61A | 8
# 6  | American Pale Ale, India Pale Ale               | #D5BC26 | 12
# 8  | Weissbier, Saison                               | #BF923B | 16
# 10  | English Bitter, ESB                            | #BF813A | 20
# 13  | Biere de Garde, Double IPA                     | #BC6733 | 26
# 17  | Dark lager, Vienna lager, Marzen, Amber Ale    | #8D4C32 | 33
# 20  | Brown Ale, Bock, Dunkel, Dunkelweizen          | #5D341A | 39
# 24  | Irish Dry Stout, Doppelbock, Porter            | #261716 | 47
# 29  | Stout                                          | #0F0B0A | 57
# 35  | Foreign Stout, Baltic Porter                   | #080707 | 69
# 40+  | Imperial Stout                                | #030403 | 79

  t.references :brewery   # optional (for now)
  t.references :brand     # optional (for now)


  ## todo: add categories e.g. (A/B/C, 1/2/3, main/major/minor ??)
  # - A-grade /1st class/ tier1 / main beer brand/bestseller/flagship ?
  # - B-grade /2nd class/ tier2 / regular, major,   - todo: find better names?
  # - C-grade /3nd class/ tier3/ / speciality, minor ?

  t.integer :grade   # 1/2/3  (A/B/C)

  t.references :country,  :null => false
  t.references :region   # optional
  t.references :city     # optional

  t.timestamps
end


create_table :brands do |t|   # beer families (sharing same name e.g. brand)
  t.string  :key,   :null => false   # import/export key
  t.string  :title, :null => false
  t.string  :synonyms  # comma separated list of synonyms
  t.string  :web   # optional web page (e.g. www.ottakringer.at)
  t.string  :wiki  # optional wiki(pedia page)
  t.integer :since

  ## scope of brand (global/intern'l/national/regional/local) ??
  t.boolean :global,     :null => false, :default => false 
  t.boolean :internl,    :null => false, :default => false
  t.boolean :national,   :null => false, :default => false
  t.boolean :regional,   :null => false, :default => false
  t.boolean :local,      :null => false, :default => false

  t.integer :grade   # 1/2/3/4/5  (global/intern'l/national/regional/local)

  t.references :brewery   # optional (for now)

  t.references :country,   :null => false
  t.references :region   # optional
  t.references :city     # optional

  t.timestamps
end

create_table :breweries do |t|
  t.string  :key,   :null => false   # import/export key
  t.string  :title, :null => false
  t.string  :synonyms  # comma separated list of synonyms
  t.string  :address
  t.integer :since
  ## renamed to founded to since
  ## t.integer :founded  # year founded/established    - todo/fix: rename to since? 
  t.integer :closed  # optional;  year brewery closed

## todo: add optional parent brewery (owned_by)

  t.integer :prod  # (estimated) annual production/capacity in hl (1hl=100l) e.g. megabrewery 2_000_000, microbrewery 1_000 hl; brewbup 500 hl etc.

  # grade - classified using annual production (capacity) in hl
  # <     1_000 hl  => 11
  # <     3_000 hl  => 10
  # <     5_000 hl  => 9
  # <    10_000 hl  => 8
  # <    50_000 hl  => 7
  # <   100_000 hl  => 6
  # <   200_000 hl  => 5
  # <   500_000 hl  => 4
  # < 1_000_000 hl  => 3
  # < 2_000_000 hl  => 2
  # > 2_000_000 hl  => 1

  t.integer :grade   # 1/2/3/4/5/6/7/8/9/10/11


  t.string  :web   # optional web page (e.g. www.ottakringer.at)
  t.string  :wiki  # optional wiki(pedia page)

  t.boolean :indie    # independent brewery (flag)

  # for convenience (easy queries) use flags for top beer multinationals (-- later use just tags? more flexible)
  t.boolean :abinbev     # owned by AB InBev / Anheuser-Busch InBev (and Grupo Modelo)
  t.boolean :sabmiller   # owned by SAB Miller (in US cooperates w/ Molson Coors using MillerCoors venture)
  t.boolean :heineken    # owned by Heineken
  t.boolean :carlsberg   # owned by Carlsberg
  t.boolean :molsoncoors  # owned by Molson Coors
  t.boolean :diageo       # owned by Diageo (e.g. Guiness, Kilkenny,...)


  # todo: add t.references :parent  # for parent brewery
  # (or better use has many parents w/ percentage of ownership; might not be 100%)

  t.references :country,   :null => false
  t.references :region   # optional
  t.references :city     # optional
  
  t.timestamps
end

end