-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): update schema + migration script
- Loading branch information
Showing
5 changed files
with
844 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
CREATE TABLE IF NOT EXISTS "problem_tags" ( | ||
"problem_id" uuid NOT NULL, | ||
"tag_id" uuid NOT NULL, | ||
CONSTRAINT "problem_tags_problem_id_tag_id_pk" PRIMARY KEY("problem_id","tag_id") | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "problems" ( | ||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
"pid" varchar(50) NOT NULL, | ||
"name" varchar(100) NOT NULL, | ||
"url" varchar(255) NOT NULL, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"updated_at" timestamp DEFAULT now() NOT NULL, | ||
"difficulty" integer, | ||
"metadata" json DEFAULT '{}'::json, | ||
CONSTRAINT "problems_pid_unique" UNIQUE("pid") | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "submissions" ( | ||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
"solve_time" integer, | ||
"verdict" varchar, | ||
"solved_at" date, | ||
"user_id" uuid NOT NULL, | ||
"problem_id" uuid NOT NULL, | ||
"is_verified" boolean DEFAULT false, | ||
"ac_count" integer DEFAULT 0, | ||
"ps_count" integer DEFAULT 0, | ||
"wa_count" integer DEFAULT 0, | ||
"tle_count" integer DEFAULT 0, | ||
"mle_count" integer DEFAULT 0, | ||
"re_count" integer DEFAULT 0, | ||
"ce_count" integer DEFAULT 0, | ||
"sk_count" integer DEFAULT 0, | ||
"hck_count" integer DEFAULT 0, | ||
"oth_count" integer DEFAULT 0, | ||
"metadata" json DEFAULT '{}'::json, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"updated_at" timestamp DEFAULT now() NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "tags" ( | ||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
"name" varchar(50) NOT NULL, | ||
CONSTRAINT "tags_name_unique" UNIQUE("name") | ||
); | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "problem_tags" ADD CONSTRAINT "problem_tags_problem_id_problems_id_fk" FOREIGN KEY ("problem_id") REFERENCES "public"."problems"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "problem_tags" ADD CONSTRAINT "problem_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "submissions" ADD CONSTRAINT "submissions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "submissions" ADD CONSTRAINT "submissions_problem_id_problems_id_fk" FOREIGN KEY ("problem_id") REFERENCES "public"."problems"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; |
Oops, something went wrong.