Skip to content

Commit 5896131

Browse files
hugoliu-codeh1divpAlexanderWangY
authored
TECH-125: Create Application Schema (#36)
* Created Goose Migration for Applications * sqlc generate * improvement: updated fields * fix: updated env path * fix: syntax * chore: sqlc generate * feat: add more columns and auto updates + withdrawn status * chore: generate sqlc types for new schema * feat: indexes and default for application body --------- Co-authored-by: h1divp <71522316+h1divp@users.noreply.github.com> Co-authored-by: Alexander Wang <alexander.yisu.wang@outlook.com>
1 parent c000ea1 commit 5896131

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

apps/api/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include .env.local
1+
include .env.dev
22

33
migrate-up:
44
@goose -dir ./internal/db/migrations postgres ${DATABASE_URL_MIGRATIONS} up
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
4+
CREATE TYPE application_status AS ENUM ('started', 'submitted', 'under_review', 'accepted', 'rejected', 'waitlisted', 'withdrawn');
5+
6+
CREATE TABLE applications (
7+
user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
8+
event_id UUID REFERENCES events(id) ON DELETE CASCADE,
9+
status application_status DEFAULT 'started',
10+
application JSONB NOT NULL DEFAULT '{}'::JSONB,
11+
resume_url TEXT,
12+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
13+
saved_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
14+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
15+
16+
PRIMARY KEY (user_id, event_id)
17+
);
18+
19+
CREATE INDEX idx_applications_status ON applications(status);
20+
CREATE INDEX idx_applications_event_id ON applications(event_id);
21+
22+
-- Create trigger to update application updates
23+
CREATE TRIGGER set_updated_at_applications
24+
BEFORE UPDATE ON applications
25+
FOR EACH ROW
26+
EXECUTE FUNCTION update_modified_column();
27+
28+
-- +goose StatementEnd
29+
30+
-- +goose Down
31+
-- +goose StatementBegin
32+
33+
34+
DROP TRIGGER IF EXISTS set_updated_at_applications ON applications;
35+
DROP TABLE IF EXISTS applications;
36+
DROP TYPE IF EXISTS application_status;
37+
38+
-- +goose StatementEnd

apps/api/internal/db/sqlc/models.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)