This repository has been archived by the owner on May 20, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
162 lines (132 loc) · 4.87 KB
/
db.sql
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
create type user_state as enum ('onboarding', 'inprogress', 'completed', 'pending', 'ready', 'invited');
create type submission_state as enum ('pending', 'accepted', 'rejected');
create table if not exists users (
user_id serial not null constraint users_pk primary key,
display_name text,
first_name text,
last_name text,
age integer,
address text,
phone text,
email text not null,
parent_email text,
no_shipping boolean default false not null,
referrer integer,
international boolean default false not null,
project_id_override integer default -1 not null,
discord_id text,
created_at timestamp not null,
updated_at timestamp not null,
state user_state default 'onboarding' :: user_state not null,
admin boolean default false,
banned boolean default false,
points int default 0 not null,
current_week int default -1 not null,
current_project int default -1 not null,
prev_projects int[] default array[]::int[] not null,
prev_modules int[] default array[]::int[] not null,
project_pool int[] default array[]::int[] not null,
badges int[] default array[]::int[] not null,
current_session text
);
create table if not exists projects (
project_id serial not null constraint projects_pk primary key,
title text not null,
description text not null,
type text not null,
thumbnail_url text not null,
enabled bool not null default false,
hardware bool not null default false,
completion_badges int[] default array[]::int[] not null
);
create table if not exists modules (
module_id serial not null constraint modules_pk primary key,
title text not null,
enabled bool not null default false,
description text not null,
content text not null,
rendered_content text not null,
points int not null,
required bool not null default false,
notion_link text,
project_id serial not null,
constraint project_fk
foreign key (project_id) references projects(project_id)
on update set null
on delete set null
);
create table if not exists badges (
badge_id serial not null constraint badges_pk primary key,
name text not null,
description text not null,
icon text not null,
hidden bool not null default false,
code text not null
);
create table if not exists submissions (
submission_id serial not null constraint submissions_pk primary key,
created_at timestamp not null,
user_id serial not null,
project_id serial not null,
module_id serial not null,
content text not null,
state submission_state default 'pending' :: submission_state not null,
comments text,
constraint user_fk
foreign key (user_id) references users(user_id)
on update set null
on delete set null,
constraint project_fk
foreign key (project_id) references projects(project_id)
on update set null
on delete set null,
constraint module_fk
foreign key (module_id) references modules(module_id)
on update set null
on delete set null
);
create table config (
key text not null constraint config_pk primary key,
value text
);
create table rewards (
reward_id serial not null constraint rewards_pk primary key,
name text not null,
description text not null,
image text not null,
quantity integer not null,
needs_shipping boolean default false not null,
enabled boolean default false not null,
raffle boolean default false not null,
price integer not null,
delivery text not null,
international boolean default false not null
);
create table orders (
order_id serial not null constraint orders_pk primary key,
ordered_at timestamp not null,
updated_at timestamp,
user_id serial not null,
reward_id serial not null,
reward_name text not null,
quantity integer not null default 1,
email text,
address text,
status text not null,
constraint reward_fk
foreign key (reward_id) references rewards(reward_id)
on update set null
on delete set null,
constraint user_fk
foreign key (user_id) references users(user_id)
on update set null
on delete set null
);
create unique index if not exists users_user_id_uindex_2 on users (user_id);
create unique index if not exists projects_project_id_uindex on projects (project_id);
create unique index if not exists modules_module_id_uindex on modules (module_id);
create unique index if not exists badges_badge_id_uindex on badges (badge_id);
create unique index if not exists submissions_submission_id_uindex on submissions (submission_id);
create unique index if not exists config_key_uindex on config (key);
create unique index if not exists rewards_reward_id_uindex on rewards (reward_id);
create unique index if not exists orders_order_id_uindex on orders (order_id);