Skip to content

Commit a5603d4

Browse files
authored
Merge pull request #68 from crux-bphc/chore/cleanup
Pre-release db and build changes
2 parents d174240 + 5773ef6 commit a5603d4

File tree

10 files changed

+666
-1399
lines changed

10 files changed

+666
-1399
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ The official Competitive Coding website for BITS Pilani, Hyderabad Campus. Surge
6464
docker compose --profile prod down
6565
```
6666

67+
## Migrations
68+
**Make sure you have the dev profile up and running before running migrations.**
69+
70+
71+
The two containers required to run and generate migrations are:
72+
- `backend-dev`
73+
- `postgres`
74+
75+
After the above mentioned containers are running you can use the following commands
76+
77+
### Apply existing migrations
78+
```bash
79+
docker compose exec backend-dev npx drizzle-kit migrate
80+
```
81+
82+
Runs migrations which haven't been applied yet. A list of migrations which have been applied is stored in a table in the database itself. Read more about this [here](https://github.com/jbranchaud/til/blob/master/drizzle/drizzle-tracks-migrations-in-a-log-table.md).
83+
84+
### Apply current schema to the database
85+
```bash
86+
docker compose exec backend-dev npx drizzle-kit push
87+
```
88+
This command **does not** generate migrations! Make sure to generate migrations for any major changes to ensure that the history of the database schema is always preserved.
89+
90+
91+
### Generate migrations from schema
92+
```bash
93+
docker compose exec backend-dev npx drizzle-kit generate
94+
```
95+
This compares the current state of the database with the schema and generates migrations.
96+
97+
6798
## Contribution
6899

69100
Follow the [Contributing Guide](./CONTRIBUTING.md).

backend/docker/prod/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ FROM node:22.17-bookworm
22

33
WORKDIR /app
44

5-
COPY ./backend .
5+
COPY ./backend/package*.json ./
6+
COPY ./backend/tsconfig.json ./
67

78
RUN npm install
9+
10+
COPY ./backend .
811
RUN npm run build
912

1013
CMD ["sh", "-c", "npm run start"]

backend/src/drizzle/0001_store_cf_data.sql renamed to backend/src/drizzle/0000_init.sql

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*
21
CREATE TYPE "public"."verdict" AS ENUM('AC', 'WA', 'TLE', 'RE', 'CE', 'other');--> statement-breakpoint
32
CREATE TABLE "cf_user_stats" (
43
"id" serial PRIMARY KEY NOT NULL,
@@ -68,20 +67,26 @@ CREATE TABLE "user_contests" (
6867
"update_time" timestamp(0)
6968
);
7069
--> statement-breakpoint
71-
ALTER TABLE "_prisma_migrations" DISABLE ROW LEVEL SECURITY;--> statement-breakpoint
72-
DROP TABLE "_prisma_migrations" CASCADE;--> statement-breakpoint
73-
ALTER TABLE "User" RENAME TO "users";--> statement-breakpoint
74-
ALTER TABLE "users" RENAME COLUMN "pfpUrl" TO "pfp_url";--> statement-breakpoint
75-
ALTER TABLE "users" RENAME COLUMN "cfHandle" TO "cf_handle";--> statement-breakpoint
76-
ALTER TABLE "users" RENAME COLUMN "cfRating" TO "cf_rating";--> statement-breakpoint
77-
ALTER TABLE "users" RENAME COLUMN "createdAt" TO "created_at";--> statement-breakpoint
78-
DROP INDEX "User_cfHandle_key";--> statement-breakpoint
79-
DROP INDEX "User_email_key";--> statement-breakpoint
80-
ALTER TABLE "users" ADD COLUMN "codechef_handle" text;--> statement-breakpoint
81-
ALTER TABLE "users" ADD COLUMN "codechef_rating" integer;--> statement-breakpoint
82-
ALTER TABLE "users" ADD COLUMN "atcoder_handle" text;--> statement-breakpoint
83-
ALTER TABLE "users" ADD COLUMN "atcoder_rating" integer;--> statement-breakpoint
84-
ALTER TABLE "users" ADD COLUMN "leetcode_handle" text;--> statement-breakpoint
70+
CREATE TABLE "users" (
71+
"id" text PRIMARY KEY NOT NULL,
72+
"email" text NOT NULL,
73+
"name" text,
74+
"pfp_url" text,
75+
"cf_handle" text,
76+
"cf_rating" integer,
77+
"codechef_handle" text,
78+
"codechef_rating" integer,
79+
"atcoder_handle" text,
80+
"atcoder_rating" integer,
81+
"leetcode_handle" text,
82+
"created_at" timestamp(3) DEFAULT now() NOT NULL,
83+
CONSTRAINT "users_email_unique" UNIQUE("email"),
84+
CONSTRAINT "users_cf_handle_unique" UNIQUE("cf_handle"),
85+
CONSTRAINT "users_codechef_handle_unique" UNIQUE("codechef_handle"),
86+
CONSTRAINT "users_atcoder_handle_unique" UNIQUE("atcoder_handle"),
87+
CONSTRAINT "users_leetcode_handle_unique" UNIQUE("leetcode_handle")
88+
);
89+
--> statement-breakpoint
8590
ALTER TABLE "cf_user_stats" ADD CONSTRAINT "cf_user_stats_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
8691
ALTER TABLE "potd" ADD CONSTRAINT "potd_problem_id_problems_id_fk" FOREIGN KEY ("problem_id") REFERENCES "public"."problems"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
8792
ALTER TABLE "potd_solves" ADD CONSTRAINT "potd_solves_potd_id_potd_id_fk" FOREIGN KEY ("potd_id") REFERENCES "public"."potd"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
@@ -92,9 +97,4 @@ ALTER TABLE "submissions" ADD CONSTRAINT "submissions_problem_id_problems_id_fk"
9297
ALTER TABLE "user_contests" ADD CONSTRAINT "user_contests_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
9398
ALTER TABLE "user_contests" ADD CONSTRAINT "user_contests_contest_id_contests_external_id_fk" FOREIGN KEY ("contest_id") REFERENCES "public"."contests"("external_id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
9499
CREATE UNIQUE INDEX "problems_contest_index" ON "problems" USING btree ("contest_id","index");--> statement-breakpoint
95-
ALTER TABLE "users" ADD CONSTRAINT "users_email_unique" UNIQUE("email");--> statement-breakpoint
96-
ALTER TABLE "users" ADD CONSTRAINT "users_cf_handle_unique" UNIQUE("cf_handle");--> statement-breakpoint
97-
ALTER TABLE "users" ADD CONSTRAINT "users_codechef_handle_unique" UNIQUE("codechef_handle");--> statement-breakpoint
98-
ALTER TABLE "users" ADD CONSTRAINT "users_atcoder_handle_unique" UNIQUE("atcoder_handle");--> statement-breakpoint
99-
ALTER TABLE "users" ADD CONSTRAINT "users_leetcode_handle_unique" UNIQUE("leetcode_handle");
100-
*/
100+
CREATE UNIQUE INDEX "user_contest_unique" ON "user_contests" USING btree ("user_id","contest_id");

backend/src/drizzle/0000_migrate_from_prisma.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.

backend/src/drizzle/0002_user_contest_unique.sql

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)