Skip to content

Commit 7393280

Browse files
authored
Merge pull request #3 from BrainNotFoundException/lavnish/DocsSchemaInit
Lavnish/docs schema init
2 parents b8913d7 + d9dde94 commit 7393280

16 files changed

Lines changed: 378 additions & 4 deletions

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ JWT_SECRET=
33

44
POSTGRES_HOST=
55
POSTGRES_PORT=
6-
POSTGRES_USER=
7-
POSTGRES_PASSWORD=
8-
POSTGRES_DB=
6+
POSTGRES_USER=abcd
7+
POSTGRES_PASSWORD=abcd
8+
POSTGRES_DB=abcd
99

1010
REDIS_HOST=
1111
REDIS_PORT=

cmd/api/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"log"
55
"os"
66

7+
"github.com/Advik-Gupta/devsoc-backend-26/pkg/router"
78
"github.com/joho/godotenv"
89
"github.com/labstack/echo/v4"
910
)
@@ -27,6 +28,8 @@ func main() {
2728
port = "8080"
2829
}
2930

31+
router.RegisterRoute(e)
32+
3033
log.Println("Server running on port", port)
3134
e.Logger.Fatal(e.Start(":" + port))
3235
}

database/schema/001_users.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- +goose Up
2+
CREATE TABLE users (
3+
id UUID PRIMARY KEY NOT NULL,
4+
team_id UUID,
5+
name TEXT NOT NULL,
6+
email TEXT UNIQUE NOT NULL,
7+
phone_no VARCHAR(10) UNIQUE,
8+
reg_no TEXT UNIQUE,
9+
gender VARCHAR(1) NOT NULL,
10+
hostel_block TEXT NOT NULL,
11+
room_no INT NOT NULL,
12+
github_profile TEXT NOT NULL,
13+
password TEXT NOT NULL,
14+
role TEXT NOT NULL,
15+
is_leader BOOLEAN NOT NULL,
16+
is_verified BOOLEAN NOT NULL,
17+
is_banned BOOLEAN NOT NULL,
18+
is_profile_complete BOOLEAN NOT NULL
19+
);
20+
21+
-- +goose Down
22+
DROP TABLE users;

database/schema/002_teams.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- +goose Up
2+
CREATE TABLE teams (
3+
id UUID PRIMARY KEY UNIQUE NOT NULL,
4+
name TEXT NOT NULL,
5+
team_size INT NOT NULL,
6+
round_qualified INT DEFAULT 0,
7+
code TEXT UNIQUE NOT NULL,
8+
is_banned BOOLEAN NOT NULL,
9+
total_score INTEGER NOT NULL DEFAULT 0
10+
);
11+
12+
-- +goose Down
13+
DROP TABLE teams;

database/schema/003_score.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- +goose Up
2+
CREATE TABLE score (
3+
id UUID PRIMARY KEY UNIQUE NOT NULL,
4+
team_id UUID NOT NULL,
5+
design INT NOT NULL DEFAULT 0,
6+
implementation INT NOT NULL DEFAULT 0,
7+
presentation INT NOT NULL DEFAULT 0,
8+
round INT NOT NULL DEFAULT 0,
9+
panel JSON NOT NULL
10+
);
11+
12+
-- +goose Down
13+
DROP TABLE score;

database/schema/004_comment.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- +goose Up
2+
CREATE TABLE comment (
3+
id UUID PRIMARY KEY UNIQUE NOT NULL,
4+
team_id UUID NOT NULL,
5+
comment JSON NOT NULL,
6+
created_by TEXT NOT NULL,
7+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
8+
);
9+
10+
-- +goose Down
11+
DROP TABLE comment;

database/schema/005_submission.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- +goose Up
2+
CREATE TABLE submission (
3+
id UUID PRIMARY KEY UNIQUE NOT NULL,
4+
title TEXT NOT NULL DEFAULT '',
5+
description TEXT NOT NULL DEFAULT '',
6+
track TEXT NOT NULL DEFAULT '',
7+
github_link TEXT NOT NULL DEFAULT '',
8+
figma_link TEXT NOT NULL DEFAULT '',
9+
other_link TEXT NOT NULL DEFAULT '',
10+
team_id UUID NOT NULL UNIQUE,
11+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
12+
);
13+
14+
-- +goose Down
15+
DROP TABLE submission;

database/schema/006_ideas.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- +goose Up
2+
CREATE TABLE ideas (
3+
id UUID PRIMARY KEY UNIQUE NOT NULL,
4+
title TEXT NOT NULL,
5+
description TEXT NOT NULL,
6+
track TEXT NOT NULL,
7+
team_id UUID NOT NULL,
8+
is_selected BOOLEAN NOT NULL DEFAULT FALSE,
9+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
10+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
11+
);
12+
13+
-- +goose Down
14+
DROP TABLE ideas;

database/schema/007_logs.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- +goose Up
2+
CREATE TABLE logs (
3+
id UUID PRIMARY KEY NOT NULL,
4+
type TEXT NOT NULL,
5+
body JSON NOT NULL,
6+
created_by TEXT NOT NULL,
7+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
8+
);
9+
10+
-- +goose Down
11+
DROP TABLE logs;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- +goose Up
2+
ALTER TABLE users ADD CONSTRAINT fk_users_team FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE SET NULL;
3+
4+
ALTER TABLE score ADD CONSTRAINT fk_score_team FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE;
5+
6+
ALTER TABLE comment ADD CONSTRAINT fk_comment_team FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE;
7+
8+
ALTER TABLE comment ADD CONSTRAINT fk_comment_user_email FOREIGN KEY (created_by) REFERENCES users(email) ON DELETE CASCADE;
9+
10+
ALTER TABLE submission ADD CONSTRAINT fk_submission_team FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE;
11+
12+
ALTER TABLE ideas ADD CONSTRAINT fk_idea_team FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE;
13+
14+
ALTER TABLE logs ADD CONSTRAINT fk_logs_user_email FOREIGN KEY (created_by) REFERENCES users(email) ON DELETE CASCADE;
15+
16+
-- +goose Down
17+
18+
ALTER TABLE users DROP fk_users_team;
19+
ALTER TABLE score DROP fk_score_team;
20+
ALTER TABLE comment DROP fk_comment_team;
21+
ALTER TABLE comment DROP fk_comment_user_email;
22+
ALTER TABLE submission DROP fk_submission_team;
23+
ALTER TABLE ideas DROP fk_idea_team;
24+
ALTER TABLE logs DROP fk_logs_user_email;

0 commit comments

Comments
 (0)