Skip to content

Commit 7185af8

Browse files
authored
Merge pull request #42 from sidvasu/new-schemas
Updated board schemas and queries
2 parents b906c2a + a87c888 commit 7185af8

2 files changed

Lines changed: 36 additions & 25 deletions

File tree

internal/db/sql/queries/board.sql

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
-- name: GetBoard :one
22
SELECT
3-
id,
4-
name,
5-
branch,
6-
github,
7-
discord,
8-
year,
9-
bio
3+
full_name,
4+
picture,
5+
discord
106
FROM
11-
board_member
7+
officers
128
WHERE
13-
id = ?;
9+
uuid = ?;
10+
11+
-- name: GetPositions :one
12+
SELECT
13+
tiers.title,
14+
tiers.team,
15+
positions.semester
16+
FROM
17+
officers
18+
INNER JOIN positions
19+
ON officers.uuid = positions.oid
20+
INNER JOIN tiers
21+
ON positions.tier = tiers.tier
22+
WHERE officers.full_name = ?

internal/db/sql/schemas/schema.sql

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,29 @@ CREATE TABLE IF NOT EXISTS announcement (
2727
--UNIQUE (id)
2828
);
2929

30-
CREATE TABLE IF NOT EXISTS board_member (
31-
id CHAR(4) PRIMARY KEY,
32-
name VARCHAR(30) NOT NULL,
33-
branch VARCHAR(20) NOT NULL,
34-
github VARCHAR(39),
35-
discord VARCHAR(32),
36-
year INT,
37-
bio TEXT
30+
CREATE TABLE IF NOT EXISTS officers (
31+
uuid CHAR(4) PRIMARY KEY,
32+
full_name VARCHAR(30) NOT NULL,
33+
picture VARCHAR(37),
34+
github VARCHAR(64),
35+
discord VARCHAR(32)
3836
);
3937

40-
CREATE TABLE IF NOT EXISTS branch (
41-
name VARCHAR(20) PRIMARY KEY
38+
CREATE TABLE IF NOT EXISTS tiers (
39+
tier INT PRIMARY KEY,
40+
title VARCHAR(40),
41+
t_index INT,
42+
team VARCHAR(20)
4243
);
4344

44-
CREATE TABLE IF NOT EXISTS member_of (
45-
bmid CHAR(4) NOT NULL,
46-
bname VARCHAR(20) NOT NULL,
47-
PRIMARY KEY (bmid, bname),
45+
CREATE TABLE IF NOT EXISTS positions (
46+
oid CHAR(4) NOT NULL,
47+
semester CHAR(3) NOT NULL,
48+
tier INT NOT NULL,
49+
PRIMARY KEY (oid, semester, tier),
4850

49-
CONSTRAINT fk_board FOREIGN KEY (bmid) REFERENCES board_member (id),
50-
CONSTRAINT fk_branch FOREIGN KEY (bname) REFERENCES branch (name)
51+
CONSTRAINT fk_officers FOREIGN KEY (oid) REFERENCES officer (uuid),
52+
CONSTRAINT fk_tiers FOREIGN KEY (tier) REFERENCES branch (tier)
5153
);
5254

5355
-- TODO: Create a table for access tokens for the API.

0 commit comments

Comments
 (0)