Repository navigation
Expand file tree
/
Copy pathschema.sql
More file actions
57 lines (51 loc) · 2.23 KB
/
Copy pathschema.sql
File metadata and controls
57 lines (51 loc) · 2.23 KB
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
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE TABLE IF NOT EXISTS hackathons (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
description TEXT NOT NULL DEFAULT '',
public_uuid UUID NOT NULL DEFAULT gen_random_uuid() UNIQUE,
status TEXT NOT NULL DEFAULT 'draft'
CHECK (status IN ('draft', 'active', 'archived')),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS teams (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
hackathon_id UUID NOT NULL REFERENCES hackathons(id) ON DELETE CASCADE,
name TEXT NOT NULL,
description TEXT NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE (hackathon_id, name)
);
CREATE TABLE IF NOT EXISTS tasks (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
hackathon_id UUID NOT NULL REFERENCES hackathons(id) ON DELETE CASCADE,
title TEXT NOT NULL,
description TEXT NOT NULL DEFAULT '',
points INTEGER NOT NULL CHECK (points >= 0),
active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS point_events (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
hackathon_id UUID NOT NULL REFERENCES hackathons(id) ON DELETE CASCADE,
team_id UUID NOT NULL REFERENCES teams(id) ON DELETE CASCADE,
type TEXT NOT NULL CHECK (type IN ('task_completion', 'adhoc')),
points INTEGER NOT NULL,
description TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS achievements (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
team_id UUID NOT NULL REFERENCES teams(id) ON DELETE CASCADE,
task_id UUID NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
points_awarded INTEGER NOT NULL,
note TEXT NOT NULL DEFAULT '',
awarded_at TIMESTAMPTZ NOT NULL DEFAULT now(),
point_event_id UUID REFERENCES point_events(id) ON DELETE CASCADE,
UNIQUE (team_id, task_id)
);
CREATE INDEX IF NOT EXISTS idx_point_events_team ON point_events (team_id, created_at);
CREATE INDEX IF NOT EXISTS idx_point_events_hackathon ON point_events (hackathon_id, created_at);
CREATE INDEX IF NOT EXISTS idx_teams_hackathon ON teams (hackathon_id);
CREATE INDEX IF NOT EXISTS idx_tasks_hackathon ON tasks (hackathon_id);