-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.rb
78 lines (69 loc) · 1.49 KB
/
model.rb
1
2
3
4
5
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
require 'rubygems'
require 'sequel'
require 'logger'
Sequel::Model.plugin(:schema)
DB = Sequel.mysql2('sandbox', user: 'root', password: '1234')
class Hero < Sequel::Model
unrestrict_primary_key
unless table_exists?
set_schema do
Integer :id, auto_increment: true
Integer :hero_type, null: false
primary_key [:id, :hero_type]
unique [:id, :hero_type]
Integer :power, null: false
Integer :dex, index: true, null: false
Integer :intelligence
boolean :paradin, null: false
Time :create_date
end
create_table
end
end
class Follower < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
text :type
text :name
timestamp :create_date
int :hero_id
end
create_table
end
many_to_one :hero
end
class Product < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
text :name
end
create_table
end
one_to_many :taggings
many_to_many :tags, :join_table => :taggings
end
class Tag < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
text :name
end
create_table
end
one_to_many :taggings
many_to_many :products, :join_table => :taggings
end
class Tagging < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
foreign_key :tag_id, :table => :tags
foreign_key :product_id, :table => :products
end
create_table
end
many_to_one :product
many_to_one :tag
end