summaryrefslogtreecommitdiff
path: root/db/kanta.sql
blob: e6b4fb925d32292ca87b77eff4a7d2a86c682069 (plain)
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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
-- set GLOBAL time_zone = '+00:00';
pragma foreign_keys = on;

-- user / organization data
drop table if exists users;
create table users (
   -- id of the user / org
   id integer not null primary key autoincrement,
   -- creation time
   created_at timestamp not null default current_timestamp,
   -- last update
   updated_at timestamp,
   -- is this user an organization?
   org boolean not null,
   -- email address
   email text not null unique,
   -- user / organization name
   name text not null unique,
   -- password
   pass text not null,
   -- metadata
   meta text not null default '{}'
);

-- organization level access control lists
drop table if exists org_acls;
create table org_acls (
   -- org acl id
   id integer not null primary key autoincrement,
   -- user id (user.organization == true)
   org integer not null,
   -- user id (member of the organization)
   member integer not null,
   -- ACL bits (what the member can do in the organization)
   rights integer not null,
   -- relationships
   foreign key (org) references users (id),
   foreign key (member) references users (id)
);

-- engines
drop table if exists engines;
create table engines (
   -- id of the engine
   id integer not null primary key autoincrement,
   -- engine name
   name text not null,
   -- extra metadata
   meta text not null default '{}'
);

-- products
drop table if exists products;
create table products (
   -- id of the product
   id integer not null primary key autoincrement,
   -- creation time
   created_at timestamp not null default current_timestamp,
   -- last update
   updated_at timestamp,
   -- engine id
   engine integer not null,
   -- supported platforms
   platforms integer not null,
   -- price
   price integer not null,
   -- title
   title text not null,
   -- description
   body text not null,
   -- short description
   short text not null,
   -- header image
   header text not null,
   -- extra metadata
   meta text not null default '{}',
   -- relationships
   foreign key (engine) references engines (id)
);

-- tags
drop table if exists tags;
create table tags (
   -- id of the tag
   id integer not null primary key autoincrement,
   -- tag name
   name text not null,
   -- extra metadata
   meta text not null default '{}'
);

-- product tags
drop table if exists product_tags;
create table product_tags (
   -- product tag id
   id integer not null primary key autoincrement,
   -- product id
   product integer not null,
   -- tag id
   tag integer not null,
   -- relationships
   foreign key (product) references products (id),
   foreign key (tag) references roles (id)
);

-- product level access control lists
drop table if exists product_acls;
create table product_acls (
   -- product acl id
   id integer not null primary key autoincrement,
   -- product id
   product integer not null,
   -- user id
   member integer not null,
   -- ACL bits (what the member can do with the product)
   rights integer not null,
   -- relationships
   foreign key (member) references users (id),
   foreign key (product) references products (id)
);

-- roles
drop table if exists roles;
create table roles (
   -- id of the role
   id integer not null primary key autoincrement,
   -- name of the role
   name text not null
);

-- creators
drop table if exists creators;
create table creators (
   -- id of the creator
   id integer not null primary key autoincrement,
   -- creation time
   created_at timestamp not null default current_timestamp,
   -- last update
   updated_at timestamp,
   -- name of the creator
   name text not null,
   -- extra metadata
   meta text not null default '{}'
);

-- product creators
drop table if exists product_creators;
create table product_creators (
   -- product creator id
   id integer not null primary key autoincrement,
   -- creator id
   creator integer not null,
   -- product id
   product integer not null,
   -- role id
   role integer not null,
   -- relationships
   foreign key (creator) references creators (id),
   foreign key (product) references products (id),
   foreign key (role) references roles (id)
);

-- product reviews
drop table if exists reviews;
create table reviews (
   -- review id
   id integer not null primary key autoincrement,
   -- creation time
   created_at timestamp not null default current_timestamp,
   -- last update
   updated_at timestamp,
   -- product id
   product integer not null,
   -- rating
   rating integer not null,
   -- title
   title text not null,
   -- body
   body text not null,
   -- relationships
   foreign key (product) references products (id)
);