feat(阶段1): drizzle schema 从本地库生成并剪掉 Django 框架表
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
12
apps/api/drizzle.config.ts
Normal file
12
apps/api/drizzle.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { defineConfig } from "drizzle-kit"
|
||||
|
||||
export default defineConfig({
|
||||
dialect: "postgresql",
|
||||
schema: "./src/db/schema.ts",
|
||||
out: "./src/db",
|
||||
dbCredentials: {
|
||||
url: process.env.DATABASE_URL ?? "postgres://onlinejudge:onlinejudge@localhost:5433/onlinejudge",
|
||||
},
|
||||
// Django 框架表不进新后端,introspect 时直接排除
|
||||
tablesFilter: ["!django_*", "!auth_*"],
|
||||
})
|
||||
20
apps/api/package.json
Normal file
20
apps/api/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@oj2/api",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "bun --watch src/index.ts",
|
||||
"db:pull": "drizzle-kit pull"
|
||||
},
|
||||
"dependencies": {
|
||||
"@oj2/contract": "workspace:*",
|
||||
"drizzle-orm": "^0.45.2",
|
||||
"hono": "^4.0.0",
|
||||
"postgres": "^3.4.0",
|
||||
"zod": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"drizzle-kit": "^0.31.10"
|
||||
}
|
||||
}
|
||||
453
apps/api/src/db/0000_crazy_gateway.sql
Normal file
453
apps/api/src/db/0000_crazy_gateway.sql
Normal file
@@ -0,0 +1,453 @@
|
||||
-- Current sql file was generated after introspecting the database
|
||||
-- If you want to run this migration please uncomment this code before executing migrations
|
||||
/*
|
||||
CREATE SEQUENCE "public"."auth_group_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1;--> statement-breakpoint
|
||||
CREATE SEQUENCE "public"."auth_group_permissions_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1;--> statement-breakpoint
|
||||
CREATE SEQUENCE "public"."auth_permission_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1;--> statement-breakpoint
|
||||
CREATE SEQUENCE "public"."django_content_type_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1;--> statement-breakpoint
|
||||
CREATE SEQUENCE "public"."django_migrations_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1;--> statement-breakpoint
|
||||
CREATE TABLE "ai_analysis" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "ai_analysis_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"provider" text NOT NULL,
|
||||
"data" jsonb NOT NULL,
|
||||
"system_prompt" text NOT NULL,
|
||||
"user_prompt" text NOT NULL,
|
||||
"analysis" text NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"model" text NOT NULL,
|
||||
"is_pinned" boolean NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "announcement" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"content" text NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"last_update_time" timestamp with time zone NOT NULL,
|
||||
"visible" boolean NOT NULL,
|
||||
"created_by_id" integer NOT NULL,
|
||||
"tag" text NOT NULL,
|
||||
"top" boolean NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "achievement" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "achievement_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"name" text NOT NULL,
|
||||
"description" text NOT NULL,
|
||||
"icon" text NOT NULL,
|
||||
"rarity" text NOT NULL,
|
||||
"hidden" boolean DEFAULT false NOT NULL,
|
||||
"metric" text NOT NULL,
|
||||
"operator" text NOT NULL,
|
||||
"threshold" integer NOT NULL,
|
||||
"visible" boolean DEFAULT true NOT NULL,
|
||||
"unlock_count" integer DEFAULT 0 NOT NULL,
|
||||
"order" integer DEFAULT 0 NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "contest" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"description" text NOT NULL,
|
||||
"password" text,
|
||||
"start_time" timestamp with time zone NOT NULL,
|
||||
"end_time" timestamp with time zone NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"last_update_time" timestamp with time zone NOT NULL,
|
||||
"visible" boolean NOT NULL,
|
||||
"created_by_id" integer NOT NULL,
|
||||
"allowed_ip_ranges" jsonb NOT NULL,
|
||||
"tag" text NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "contest_announcement" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"content" text NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"contest_id" integer NOT NULL,
|
||||
"created_by_id" integer NOT NULL,
|
||||
"visible" boolean NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "flowchart_submission" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"mermaid_code" text NOT NULL,
|
||||
"flowchart_data" jsonb NOT NULL,
|
||||
"status" integer NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"ai_score" double precision,
|
||||
"ai_grade" varchar(10),
|
||||
"ai_feedback" text,
|
||||
"ai_suggestions" text,
|
||||
"ai_criteria_details" jsonb NOT NULL,
|
||||
"ai_provider" varchar(50) NOT NULL,
|
||||
"ai_model" varchar(50) NOT NULL,
|
||||
"processing_time" double precision,
|
||||
"evaluation_time" timestamp with time zone,
|
||||
"problem_id" integer NOT NULL,
|
||||
"user_id" integer NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "message" (
|
||||
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "message_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"message" text NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"recipient_id" integer NOT NULL,
|
||||
"sender_id" integer NOT NULL,
|
||||
"submission_id" text NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "judge_server" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"hostname" text NOT NULL,
|
||||
"ip" text,
|
||||
"judger_version" text NOT NULL,
|
||||
"cpu_core" integer NOT NULL,
|
||||
"memory_usage" double precision NOT NULL,
|
||||
"cpu_usage" double precision NOT NULL,
|
||||
"last_heartbeat" timestamp with time zone NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"task_number" integer NOT NULL,
|
||||
"service_url" text,
|
||||
"is_disabled" boolean NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "exercise" (
|
||||
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "exercise_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"type" varchar(16) NOT NULL,
|
||||
"data" jsonb NOT NULL,
|
||||
"order" integer NOT NULL,
|
||||
"created_at" timestamp with time zone NOT NULL,
|
||||
"tutorial_id" integer NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "options_sysoptions" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"key" text NOT NULL,
|
||||
"value" jsonb NOT NULL,
|
||||
CONSTRAINT "options_sysoptions_key_key" UNIQUE("key")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "problemset" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "problemset_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"title" text NOT NULL,
|
||||
"description" text NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"last_update_time" timestamp with time zone NOT NULL,
|
||||
"visible" boolean NOT NULL,
|
||||
"difficulty" text NOT NULL,
|
||||
"status" text NOT NULL,
|
||||
"created_by_id" integer NOT NULL,
|
||||
"end_time" timestamp with time zone
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "problemset_problem" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "problemset_problem_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"order" integer NOT NULL,
|
||||
"is_required" boolean NOT NULL,
|
||||
"score" integer NOT NULL,
|
||||
"hint" text,
|
||||
"problem_id" integer NOT NULL,
|
||||
"problemset_id" bigint NOT NULL,
|
||||
CONSTRAINT "unique_problemset_problem" UNIQUE("problem_id","problemset_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "problemset_progress" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "problemset_progress_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"join_time" timestamp with time zone NOT NULL,
|
||||
"complete_time" timestamp with time zone,
|
||||
"is_completed" boolean NOT NULL,
|
||||
"progress_percentage" double precision NOT NULL,
|
||||
"completed_problems_count" integer NOT NULL,
|
||||
"total_problems_count" integer NOT NULL,
|
||||
"total_score" integer NOT NULL,
|
||||
"progress_detail" jsonb NOT NULL,
|
||||
"problemset_id" bigint NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
CONSTRAINT "unique_problemset_progress_user" UNIQUE("problemset_id","user_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "problemset_submission" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "problemset_submission_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"problem_id" integer NOT NULL,
|
||||
"problemset_id" bigint NOT NULL,
|
||||
"submission_id" text NOT NULL,
|
||||
"user_id" integer NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "reaction" (
|
||||
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "reaction_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"type" varchar(20) NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"problem_id" integer NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
CONSTRAINT "reaction_problem_user_unique" UNIQUE("problem_id","user_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "problem" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"description" text NOT NULL,
|
||||
"input_description" text NOT NULL,
|
||||
"output_description" text NOT NULL,
|
||||
"samples" jsonb NOT NULL,
|
||||
"test_case_id" text NOT NULL,
|
||||
"test_case_score" jsonb NOT NULL,
|
||||
"hint" text,
|
||||
"languages" jsonb NOT NULL,
|
||||
"template" jsonb NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"last_update_time" timestamp with time zone,
|
||||
"time_limit" integer NOT NULL,
|
||||
"memory_limit" integer NOT NULL,
|
||||
"visible" boolean DEFAULT true NOT NULL,
|
||||
"difficulty" text NOT NULL,
|
||||
"source" text,
|
||||
"submission_number" bigint DEFAULT 0 NOT NULL,
|
||||
"accepted_number" bigint DEFAULT 0 NOT NULL,
|
||||
"created_by_id" integer NOT NULL,
|
||||
"_id" text NOT NULL,
|
||||
"statistic_info" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"contest_id" integer,
|
||||
"is_public" boolean DEFAULT false NOT NULL,
|
||||
"share_submission" boolean DEFAULT false NOT NULL,
|
||||
"prompt" text,
|
||||
"answers" jsonb,
|
||||
"allow_flowchart" boolean DEFAULT false NOT NULL,
|
||||
"flowchart_data" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"flowchart_hint" text,
|
||||
"mermaid_code" text,
|
||||
"show_flowchart" boolean DEFAULT false NOT NULL,
|
||||
"ast_rules" jsonb,
|
||||
"sql_config" jsonb,
|
||||
"sql_display" jsonb,
|
||||
CONSTRAINT "unique_problem_id_contest" UNIQUE("_id","contest_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "problem_tags" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"problem_id" integer NOT NULL,
|
||||
"problemtag_id" integer NOT NULL,
|
||||
CONSTRAINT "problem_tags_problem_id_problemtag_id_318459d1_uniq" UNIQUE("problem_id","problemtag_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "problem_tag" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" text NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "submission" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"contest_id" integer,
|
||||
"problem_id" integer NOT NULL,
|
||||
"create_time" timestamp with time zone NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"code" text NOT NULL,
|
||||
"result" integer DEFAULT 6 NOT NULL,
|
||||
"info" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"language" text NOT NULL,
|
||||
"shared" boolean DEFAULT false NOT NULL,
|
||||
"statistic_info" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"username" text NOT NULL,
|
||||
"ip" text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "tutorial" (
|
||||
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "tutorial_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"title" varchar(128) NOT NULL,
|
||||
"content" text NOT NULL,
|
||||
"created_at" timestamp with time zone NOT NULL,
|
||||
"updated_at" timestamp with time zone NOT NULL,
|
||||
"is_public" boolean NOT NULL,
|
||||
"order" integer NOT NULL,
|
||||
"created_by_id" integer NOT NULL,
|
||||
"code" text,
|
||||
"type" varchar(10) NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "user_stat" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "user_stat_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"metrics" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"update_time" timestamp with time zone NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
CONSTRAINT "user_stat_user_id_key" UNIQUE("user_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "user_achievement" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "user_achievement_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"unlock_time" timestamp with time zone NOT NULL,
|
||||
"backfilled" boolean DEFAULT false NOT NULL,
|
||||
"notified" boolean DEFAULT false NOT NULL,
|
||||
"achievement_id" bigint NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
CONSTRAINT "unique_user_achievement" UNIQUE("achievement_id","user_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "user_badge" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "user_badge_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"earned_time" timestamp with time zone NOT NULL,
|
||||
"badge_id" bigint NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
CONSTRAINT "unique_user_badge" UNIQUE("badge_id","user_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "user_profile" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"acm_problems_status" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"avatar" text NOT NULL,
|
||||
"blog" varchar(200),
|
||||
"mood" text,
|
||||
"accepted_number" integer DEFAULT 0 NOT NULL,
|
||||
"submission_number" integer DEFAULT 0 NOT NULL,
|
||||
"github" text,
|
||||
"school" text,
|
||||
"major" text,
|
||||
"user_id" integer NOT NULL,
|
||||
"real_name" text,
|
||||
"language" text,
|
||||
CONSTRAINT "user_profile_user_id_key" UNIQUE("user_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "acm_contest_rank" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"submission_number" integer DEFAULT 0 NOT NULL,
|
||||
"accepted_number" integer DEFAULT 0 NOT NULL,
|
||||
"total_time" integer DEFAULT 0 NOT NULL,
|
||||
"submission_info" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"contest_id" integer NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
CONSTRAINT "unique_acm_rank_user_contest" UNIQUE("contest_id","user_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "user" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"password" varchar(128) NOT NULL,
|
||||
"last_login" timestamp with time zone,
|
||||
"username" text NOT NULL,
|
||||
"email" text,
|
||||
"create_time" timestamp with time zone,
|
||||
"admin_type" text NOT NULL,
|
||||
"auth_token" text,
|
||||
"open_api" boolean DEFAULT false NOT NULL,
|
||||
"open_api_appkey" text,
|
||||
"is_disabled" boolean DEFAULT false NOT NULL,
|
||||
"problem_permission" text NOT NULL,
|
||||
"session_keys" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
"raw_password" varchar(20),
|
||||
"class_name" text,
|
||||
CONSTRAINT "user_username_key" UNIQUE("username")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "problemset_badge" (
|
||||
"id" bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "problemset_badge_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
|
||||
"name" text NOT NULL,
|
||||
"description" text NOT NULL,
|
||||
"icon" text NOT NULL,
|
||||
"condition_type" text NOT NULL,
|
||||
"condition_value" integer NOT NULL,
|
||||
"problemset_id" bigint NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "ai_analysis" ADD CONSTRAINT "ai_analysis_user_id_3aa23011_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "announcement" ADD CONSTRAINT "announcement_created_by_id_359ccf50_fk_user_id" FOREIGN KEY ("created_by_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "contest" ADD CONSTRAINT "contest_created_by_id_a763ca7e_fk_user_id" FOREIGN KEY ("created_by_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "contest_announcement" ADD CONSTRAINT "contest_announcement_contest_id_a8cb419f_fk_contest_id" FOREIGN KEY ("contest_id") REFERENCES "public"."contest"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "contest_announcement" ADD CONSTRAINT "contest_announcement_created_by_id_469a14ce_fk_user_id" FOREIGN KEY ("created_by_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "flowchart_submission" ADD CONSTRAINT "flowchart_submission_problem_id_8551edbf_fk_problem_id" FOREIGN KEY ("problem_id") REFERENCES "public"."problem"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "flowchart_submission" ADD CONSTRAINT "flowchart_submission_user_id_225c83e8_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "message" ADD CONSTRAINT "message_recipient_id_2aa5dd76_fk_user_id" FOREIGN KEY ("recipient_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "message" ADD CONSTRAINT "message_sender_id_a2a2e825_fk_user_id" FOREIGN KEY ("sender_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "message" ADD CONSTRAINT "message_submission_id_2fdf8a47_fk_submission_id" FOREIGN KEY ("submission_id") REFERENCES "public"."submission"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "exercise" ADD CONSTRAINT "exercise_tutorial_id_6fd04055_fk_tutorial_id" FOREIGN KEY ("tutorial_id") REFERENCES "public"."tutorial"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset" ADD CONSTRAINT "problemset_created_by_id_01b5197f_fk_user_id" FOREIGN KEY ("created_by_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_problem" ADD CONSTRAINT "problemset_problem_problem_id_fff2d686_fk_problem_id" FOREIGN KEY ("problem_id") REFERENCES "public"."problem"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_problem" ADD CONSTRAINT "problemset_problem_problemset_id_350d17fb_fk_problemset_id" FOREIGN KEY ("problemset_id") REFERENCES "public"."problemset"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_progress" ADD CONSTRAINT "problemset_progress_problemset_id_20a9632e_fk_problemset_id" FOREIGN KEY ("problemset_id") REFERENCES "public"."problemset"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_progress" ADD CONSTRAINT "problemset_progress_user_id_c8041a80_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_submission" ADD CONSTRAINT "problemset_submission_problem_id_5629b105_fk_problem_id" FOREIGN KEY ("problem_id") REFERENCES "public"."problem"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_submission" ADD CONSTRAINT "problemset_submission_problemset_id_85290e17_fk_problemset_id" FOREIGN KEY ("problemset_id") REFERENCES "public"."problemset"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_submission" ADD CONSTRAINT "problemset_submission_submission_id_78e2b807_fk_submission_id" FOREIGN KEY ("submission_id") REFERENCES "public"."submission"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_submission" ADD CONSTRAINT "problemset_submission_user_id_915fc9c6_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "reaction" ADD CONSTRAINT "reaction_problem_id_a7f3b9f3_fk_problem_id" FOREIGN KEY ("problem_id") REFERENCES "public"."problem"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "reaction" ADD CONSTRAINT "reaction_user_id_cfa7f469_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problem" ADD CONSTRAINT "problem_contest_id_328e013a_fk_contest_id" FOREIGN KEY ("contest_id") REFERENCES "public"."contest"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problem" ADD CONSTRAINT "problem_created_by_id_cb362143_fk_user_id" FOREIGN KEY ("created_by_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problem_tags" ADD CONSTRAINT "problem_tags_problem_id_866ecb8d_fk_problem_id" FOREIGN KEY ("problem_id") REFERENCES "public"."problem"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problem_tags" ADD CONSTRAINT "problem_tags_problemtag_id_72d20571_fk_problem_tag_id" FOREIGN KEY ("problemtag_id") REFERENCES "public"."problem_tag"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "submission" ADD CONSTRAINT "submission_contest_id_775716d5_fk_contest_id" FOREIGN KEY ("contest_id") REFERENCES "public"."contest"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "submission" ADD CONSTRAINT "submission_problem_id_76847b55_fk_problem_id" FOREIGN KEY ("problem_id") REFERENCES "public"."problem"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "tutorial" ADD CONSTRAINT "tutorial_created_by_id_07973cab_fk_user_id" FOREIGN KEY ("created_by_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "user_stat" ADD CONSTRAINT "user_stat_user_id_73337fc0_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "user_achievement" ADD CONSTRAINT "user_achievement_achievement_id_29db600d_fk_achievement_id" FOREIGN KEY ("achievement_id") REFERENCES "public"."achievement"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "user_achievement" ADD CONSTRAINT "user_achievement_user_id_b8ec7d6a_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "user_badge" ADD CONSTRAINT "user_badge_badge_id_92a983e9_fk_problemset_badge_id" FOREIGN KEY ("badge_id") REFERENCES "public"."problemset_badge"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "user_badge" ADD CONSTRAINT "user_badge_user_id_a286d718_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "user_profile" ADD CONSTRAINT "user_profile_user_id_8fdce8e2_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "acm_contest_rank" ADD CONSTRAINT "acm_contest_rank_contest_id_21030ccd_fk_contest_id" FOREIGN KEY ("contest_id") REFERENCES "public"."contest"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "acm_contest_rank" ADD CONSTRAINT "acm_contest_rank_user_id_40391ab2_fk_user_id" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "problemset_badge" ADD CONSTRAINT "problemset_badge_problemset_id_6cb6c74f_fk_problemset_id" FOREIGN KEY ("problemset_id") REFERENCES "public"."problemset"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "ai_analysis_user_id_3aa23011" ON "ai_analysis" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "announcement_created_by_id_359ccf50" ON "announcement" USING btree ("created_by_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "announcement_list_idx" ON "announcement" USING btree ("visible" bool_ops,"top" bool_ops,"create_time" bool_ops);--> statement-breakpoint
|
||||
CREATE INDEX "contest_created_by_id_a763ca7e" ON "contest" USING btree ("created_by_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "contest_announcement_contest_id_a8cb419f" ON "contest_announcement" USING btree ("contest_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "contest_announcement_created_by_id_469a14ce" ON "contest_announcement" USING btree ("created_by_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "flowchart_problem_time_idx" ON "flowchart_submission" USING btree ("problem_id" int4_ops,"create_time" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "flowchart_status_idx" ON "flowchart_submission" USING btree ("status" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "flowchart_submission_id_0dbfc4f9_like" ON "flowchart_submission" USING btree ("id" text_pattern_ops);--> statement-breakpoint
|
||||
CREATE INDEX "flowchart_submission_problem_id_8551edbf" ON "flowchart_submission" USING btree ("problem_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "flowchart_submission_user_id_225c83e8" ON "flowchart_submission" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "flowchart_user_time_idx" ON "flowchart_submission" USING btree ("user_id" int4_ops,"create_time" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "message_recipient_id_2aa5dd76" ON "message" USING btree ("recipient_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "message_recipient_time_idx" ON "message" USING btree ("recipient_id" timestamptz_ops,"create_time" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "message_sender_id_a2a2e825" ON "message" USING btree ("sender_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "message_submission_id_2fdf8a47" ON "message" USING btree ("submission_id" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "message_submission_id_2fdf8a47_like" ON "message" USING btree ("submission_id" text_pattern_ops);--> statement-breakpoint
|
||||
CREATE INDEX "exercise_tutorial_id_6fd04055" ON "exercise" USING btree ("tutorial_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_created_by_id_01b5197f" ON "problemset" USING btree ("created_by_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_problem_problem_id_fff2d686" ON "problemset_problem" USING btree ("problem_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_problem_problemset_id_350d17fb" ON "problemset_problem" USING btree ("problemset_id" int8_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_progress_problemset_id_20a9632e" ON "problemset_progress" USING btree ("problemset_id" int8_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_progress_user_id_c8041a80" ON "problemset_progress" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset__problem_1f39fa_idx" ON "problemset_submission" USING btree ("problemset_id" int4_ops,"user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset__problem_22f053_idx" ON "problemset_submission" USING btree ("problemset_id" int8_ops,"problem_id" int8_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset__user_id_2f1501_idx" ON "problemset_submission" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_submission_problem_id_5629b105" ON "problemset_submission" USING btree ("problem_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_submission_problemset_id_85290e17" ON "problemset_submission" USING btree ("problemset_id" int8_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_submission_submission_id_78e2b807" ON "problemset_submission" USING btree ("submission_id" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_submission_submission_id_78e2b807_like" ON "problemset_submission" USING btree ("submission_id" text_pattern_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_submission_user_id_915fc9c6" ON "problemset_submission" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "reaction_problem_id_a7f3b9f3" ON "reaction" USING btree ("problem_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "reaction_problem_type_idx" ON "reaction" USING btree ("problem_id" int4_ops,"type" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "reaction_user_id_cfa7f469" ON "reaction" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problem__id_919b1d80" ON "problem" USING btree ("_id" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problem_contest_id_328e013a" ON "problem" USING btree ("contest_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problem_contest_visible_idx" ON "problem" USING btree ("contest_id" bool_ops,"visible" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problem_created_by_id_cb362143" ON "problem" USING btree ("created_by_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problem_visible_idx" ON "problem" USING btree ("visible" bool_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problem_tags_problem_id_866ecb8d" ON "problem_tags" USING btree ("problem_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problem_tags_problemtag_id_72d20571" ON "problem_tags" USING btree ("problemtag_id" int4_ops);--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "problem_tag_name_ci_unique" ON "problem_tag" USING btree (lower(name) text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "contest_create_time_idx" ON "submission" USING btree ("contest_id" timestamptz_ops,"create_time" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problem_user_idx" ON "submission" USING btree ("problem_id" int4_ops,"user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "submission_contest_id_775716d5" ON "submission" USING btree ("contest_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "submission_problem_id_76847b55" ON "submission" USING btree ("problem_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "submission_result_37e2f67a" ON "submission" USING btree ("result" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "submission_user_id_3779a8c1" ON "submission" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "user_create_time_idx" ON "submission" USING btree ("user_id" int4_ops,"create_time" timestamptz_ops);--> statement-breakpoint
|
||||
CREATE INDEX "tutorial_created_by_id_07973cab" ON "tutorial" USING btree ("created_by_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "user_achievement_achievement_id_29db600d" ON "user_achievement" USING btree ("achievement_id" int8_ops);--> statement-breakpoint
|
||||
CREATE INDEX "user_achievement_user_id_b8ec7d6a" ON "user_achievement" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "user_achv_notified_idx" ON "user_achievement" USING btree ("user_id" int4_ops,"notified" bool_ops);--> statement-breakpoint
|
||||
CREATE INDEX "user_achv_time_idx" ON "user_achievement" USING btree ("user_id" int4_ops,"unlock_time" timestamptz_ops);--> statement-breakpoint
|
||||
CREATE INDEX "user_badge_badge_id_92a983e9" ON "user_badge" USING btree ("badge_id" int8_ops);--> statement-breakpoint
|
||||
CREATE INDEX "user_badge_user_id_a286d718" ON "user_badge" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "acm_contest_rank_contest_id_21030ccd" ON "acm_contest_rank" USING btree ("contest_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "acm_contest_rank_user_id_40391ab2" ON "acm_contest_rank" USING btree ("user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "acm_rank_contest_user_idx" ON "acm_contest_rank" USING btree ("contest_id" int4_ops,"user_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "acm_rank_order_idx" ON "acm_contest_rank" USING btree ("contest_id" int4_ops,"accepted_number" int4_ops,"total_time" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "problemset_badge_problemset_id_6cb6c74f" ON "problemset_badge" USING btree ("problemset_id" int8_ops);
|
||||
*/
|
||||
11
apps/api/src/db/index.ts
Normal file
11
apps/api/src/db/index.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js"
|
||||
import postgres from "postgres"
|
||||
|
||||
import * as schema from "./schema"
|
||||
|
||||
const url = process.env.DATABASE_URL ?? "postgres://onlinejudge:onlinejudge@localhost:5433/onlinejudge"
|
||||
|
||||
const client = postgres(url)
|
||||
|
||||
export const db = drizzle(client, { schema })
|
||||
export { schema }
|
||||
3894
apps/api/src/db/meta/0000_snapshot.json
Normal file
3894
apps/api/src/db/meta/0000_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
13
apps/api/src/db/meta/_journal.json
Normal file
13
apps/api/src/db/meta/_journal.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1786070652521,
|
||||
"tag": "0000_crazy_gateway",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
273
apps/api/src/db/relations.ts
Normal file
273
apps/api/src/db/relations.ts
Normal file
@@ -0,0 +1,273 @@
|
||||
import { relations } from "drizzle-orm/relations";
|
||||
import { user, aiAnalysis, announcement, contest, contestAnnouncement, problem, flowchartSubmission, message, submission, tutorial, exercise, problemset, problemsetProblem, problemsetProgress, problemsetSubmission, reaction, problemTags, problemTag, userStat, achievement, userAchievement, problemsetBadge, userBadge, userProfile, acmContestRank } from "./schema";
|
||||
|
||||
export const aiAnalysisRelations = relations(aiAnalysis, ({one}) => ({
|
||||
user: one(user, {
|
||||
fields: [aiAnalysis.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const userRelations = relations(user, ({many}) => ({
|
||||
aiAnalyses: many(aiAnalysis),
|
||||
announcements: many(announcement),
|
||||
contests: many(contest),
|
||||
contestAnnouncements: many(contestAnnouncement),
|
||||
flowchartSubmissions: many(flowchartSubmission),
|
||||
messages_recipientId: many(message, {
|
||||
relationName: "message_recipientId_user_id"
|
||||
}),
|
||||
messages_senderId: many(message, {
|
||||
relationName: "message_senderId_user_id"
|
||||
}),
|
||||
problemsets: many(problemset),
|
||||
problemsetProgresses: many(problemsetProgress),
|
||||
problemsetSubmissions: many(problemsetSubmission),
|
||||
reactions: many(reaction),
|
||||
problems: many(problem),
|
||||
tutorials: many(tutorial),
|
||||
userStats: many(userStat),
|
||||
userAchievements: many(userAchievement),
|
||||
userBadges: many(userBadge),
|
||||
userProfiles: many(userProfile),
|
||||
acmContestRanks: many(acmContestRank),
|
||||
}));
|
||||
|
||||
export const announcementRelations = relations(announcement, ({one}) => ({
|
||||
user: one(user, {
|
||||
fields: [announcement.createdById],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const contestRelations = relations(contest, ({one, many}) => ({
|
||||
user: one(user, {
|
||||
fields: [contest.createdById],
|
||||
references: [user.id]
|
||||
}),
|
||||
contestAnnouncements: many(contestAnnouncement),
|
||||
problems: many(problem),
|
||||
submissions: many(submission),
|
||||
acmContestRanks: many(acmContestRank),
|
||||
}));
|
||||
|
||||
export const contestAnnouncementRelations = relations(contestAnnouncement, ({one}) => ({
|
||||
contest: one(contest, {
|
||||
fields: [contestAnnouncement.contestId],
|
||||
references: [contest.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [contestAnnouncement.createdById],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const flowchartSubmissionRelations = relations(flowchartSubmission, ({one}) => ({
|
||||
problem: one(problem, {
|
||||
fields: [flowchartSubmission.problemId],
|
||||
references: [problem.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [flowchartSubmission.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const problemRelations = relations(problem, ({one, many}) => ({
|
||||
flowchartSubmissions: many(flowchartSubmission),
|
||||
problemsetProblems: many(problemsetProblem),
|
||||
problemsetSubmissions: many(problemsetSubmission),
|
||||
reactions: many(reaction),
|
||||
contest: one(contest, {
|
||||
fields: [problem.contestId],
|
||||
references: [contest.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [problem.createdById],
|
||||
references: [user.id]
|
||||
}),
|
||||
problemTags: many(problemTags),
|
||||
submissions: many(submission),
|
||||
}));
|
||||
|
||||
export const messageRelations = relations(message, ({one}) => ({
|
||||
user_recipientId: one(user, {
|
||||
fields: [message.recipientId],
|
||||
references: [user.id],
|
||||
relationName: "message_recipientId_user_id"
|
||||
}),
|
||||
user_senderId: one(user, {
|
||||
fields: [message.senderId],
|
||||
references: [user.id],
|
||||
relationName: "message_senderId_user_id"
|
||||
}),
|
||||
submission: one(submission, {
|
||||
fields: [message.submissionId],
|
||||
references: [submission.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const submissionRelations = relations(submission, ({one, many}) => ({
|
||||
messages: many(message),
|
||||
problemsetSubmissions: many(problemsetSubmission),
|
||||
contest: one(contest, {
|
||||
fields: [submission.contestId],
|
||||
references: [contest.id]
|
||||
}),
|
||||
problem: one(problem, {
|
||||
fields: [submission.problemId],
|
||||
references: [problem.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const exerciseRelations = relations(exercise, ({one}) => ({
|
||||
tutorial: one(tutorial, {
|
||||
fields: [exercise.tutorialId],
|
||||
references: [tutorial.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const tutorialRelations = relations(tutorial, ({one, many}) => ({
|
||||
exercises: many(exercise),
|
||||
user: one(user, {
|
||||
fields: [tutorial.createdById],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const problemsetRelations = relations(problemset, ({one, many}) => ({
|
||||
user: one(user, {
|
||||
fields: [problemset.createdById],
|
||||
references: [user.id]
|
||||
}),
|
||||
problemsetProblems: many(problemsetProblem),
|
||||
problemsetProgresses: many(problemsetProgress),
|
||||
problemsetSubmissions: many(problemsetSubmission),
|
||||
problemsetBadges: many(problemsetBadge),
|
||||
}));
|
||||
|
||||
export const problemsetProblemRelations = relations(problemsetProblem, ({one}) => ({
|
||||
problem: one(problem, {
|
||||
fields: [problemsetProblem.problemId],
|
||||
references: [problem.id]
|
||||
}),
|
||||
problemset: one(problemset, {
|
||||
fields: [problemsetProblem.problemsetId],
|
||||
references: [problemset.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const problemsetProgressRelations = relations(problemsetProgress, ({one}) => ({
|
||||
problemset: one(problemset, {
|
||||
fields: [problemsetProgress.problemsetId],
|
||||
references: [problemset.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [problemsetProgress.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const problemsetSubmissionRelations = relations(problemsetSubmission, ({one}) => ({
|
||||
problem: one(problem, {
|
||||
fields: [problemsetSubmission.problemId],
|
||||
references: [problem.id]
|
||||
}),
|
||||
problemset: one(problemset, {
|
||||
fields: [problemsetSubmission.problemsetId],
|
||||
references: [problemset.id]
|
||||
}),
|
||||
submission: one(submission, {
|
||||
fields: [problemsetSubmission.submissionId],
|
||||
references: [submission.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [problemsetSubmission.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const reactionRelations = relations(reaction, ({one}) => ({
|
||||
problem: one(problem, {
|
||||
fields: [reaction.problemId],
|
||||
references: [problem.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [reaction.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const problemTagsRelations = relations(problemTags, ({one}) => ({
|
||||
problem: one(problem, {
|
||||
fields: [problemTags.problemId],
|
||||
references: [problem.id]
|
||||
}),
|
||||
problemTag: one(problemTag, {
|
||||
fields: [problemTags.problemtagId],
|
||||
references: [problemTag.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const problemTagRelations = relations(problemTag, ({many}) => ({
|
||||
problemTags: many(problemTags),
|
||||
}));
|
||||
|
||||
export const userStatRelations = relations(userStat, ({one}) => ({
|
||||
user: one(user, {
|
||||
fields: [userStat.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const userAchievementRelations = relations(userAchievement, ({one}) => ({
|
||||
achievement: one(achievement, {
|
||||
fields: [userAchievement.achievementId],
|
||||
references: [achievement.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [userAchievement.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const achievementRelations = relations(achievement, ({many}) => ({
|
||||
userAchievements: many(userAchievement),
|
||||
}));
|
||||
|
||||
export const userBadgeRelations = relations(userBadge, ({one}) => ({
|
||||
problemsetBadge: one(problemsetBadge, {
|
||||
fields: [userBadge.badgeId],
|
||||
references: [problemsetBadge.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [userBadge.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const problemsetBadgeRelations = relations(problemsetBadge, ({one, many}) => ({
|
||||
userBadges: many(userBadge),
|
||||
problemset: one(problemset, {
|
||||
fields: [problemsetBadge.problemsetId],
|
||||
references: [problemset.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const userProfileRelations = relations(userProfile, ({one}) => ({
|
||||
user: one(user, {
|
||||
fields: [userProfile.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const acmContestRankRelations = relations(acmContestRank, ({one}) => ({
|
||||
contest: one(contest, {
|
||||
fields: [acmContestRank.contestId],
|
||||
references: [contest.id]
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [acmContestRank.userId],
|
||||
references: [user.id]
|
||||
}),
|
||||
}));
|
||||
652
apps/api/src/db/schema.ts
Normal file
652
apps/api/src/db/schema.ts
Normal file
@@ -0,0 +1,652 @@
|
||||
// 本文件由 `drizzle-kit pull` 从本地库自动生成,drizzle.config.ts 的 tablesFilter
|
||||
// (["!django_*", "!auth_*"]) 已生效:34 张表中的 7 张 Django 框架表
|
||||
// (auth_group、auth_group_permissions、auth_permission、django_content_type、
|
||||
// django_dramatiq_task、django_migrations、django_session) 均未生成 pgTable 定义,
|
||||
// 剩余 27 张业务表原样保留。
|
||||
//
|
||||
// 手工剪枝:tablesFilter 只过滤了 pgTable,未过滤这些框架表的 id 序列,遗留了
|
||||
// 5 个孤儿 pgSequence 导出(authGroupIdSeq、authGroupPermissionsIdSeq、
|
||||
// authPermissionIdSeq、djangoContentTypeIdSeq、djangoMigrationsIdSeq)——
|
||||
// 它们不被任何剩余表引用,留着只会在未来 `drizzle-kit generate` 时生成多余的
|
||||
// `CREATE SEQUENCE` 迁移,因此手工删除。
|
||||
import { pgTable, index, foreignKey, bigint, text, jsonb, timestamp, integer, boolean, serial, doublePrecision, varchar, unique, uniqueIndex } from "drizzle-orm/pg-core"
|
||||
import { sql } from "drizzle-orm"
|
||||
|
||||
export const aiAnalysis = pgTable("ai_analysis", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "ai_analysis_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
provider: text().notNull(),
|
||||
data: jsonb().notNull(),
|
||||
systemPrompt: text("system_prompt").notNull(),
|
||||
userPrompt: text("user_prompt").notNull(),
|
||||
analysis: text().notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
model: text().notNull(),
|
||||
isPinned: boolean("is_pinned").notNull(),
|
||||
}, (table) => [
|
||||
index("ai_analysis_user_id_3aa23011").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "ai_analysis_user_id_3aa23011_fk_user_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const announcement = pgTable("announcement", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
title: text().notNull(),
|
||||
content: text().notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
lastUpdateTime: timestamp("last_update_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
visible: boolean().notNull(),
|
||||
createdById: integer("created_by_id").notNull(),
|
||||
tag: text().notNull(),
|
||||
top: boolean().notNull(),
|
||||
}, (table) => [
|
||||
index("announcement_created_by_id_359ccf50").using("btree", table.createdById.asc().nullsLast().op("int4_ops")),
|
||||
index("announcement_list_idx").using("btree", table.visible.asc().nullsLast().op("bool_ops"), table.top.desc().nullsFirst().op("bool_ops"), table.createTime.desc().nullsFirst().op("bool_ops")),
|
||||
foreignKey({
|
||||
columns: [table.createdById],
|
||||
foreignColumns: [user.id],
|
||||
name: "announcement_created_by_id_359ccf50_fk_user_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const achievement = pgTable("achievement", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "achievement_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
name: text().notNull(),
|
||||
description: text().notNull(),
|
||||
icon: text().notNull(),
|
||||
rarity: text().notNull(),
|
||||
hidden: boolean().default(false).notNull(),
|
||||
metric: text().notNull(),
|
||||
operator: text().notNull(),
|
||||
threshold: integer().notNull(),
|
||||
visible: boolean().default(true).notNull(),
|
||||
unlockCount: integer("unlock_count").default(0).notNull(),
|
||||
order: integer().default(0).notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
});
|
||||
|
||||
export const contest = pgTable("contest", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
title: text().notNull(),
|
||||
description: text().notNull(),
|
||||
password: text(),
|
||||
startTime: timestamp("start_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
endTime: timestamp("end_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
lastUpdateTime: timestamp("last_update_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
visible: boolean().notNull(),
|
||||
createdById: integer("created_by_id").notNull(),
|
||||
allowedIpRanges: jsonb("allowed_ip_ranges").notNull(),
|
||||
tag: text().notNull(),
|
||||
}, (table) => [
|
||||
index("contest_created_by_id_a763ca7e").using("btree", table.createdById.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.createdById],
|
||||
foreignColumns: [user.id],
|
||||
name: "contest_created_by_id_a763ca7e_fk_user_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const contestAnnouncement = pgTable("contest_announcement", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
title: text().notNull(),
|
||||
content: text().notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
contestId: integer("contest_id").notNull(),
|
||||
createdById: integer("created_by_id").notNull(),
|
||||
visible: boolean().notNull(),
|
||||
}, (table) => [
|
||||
index("contest_announcement_contest_id_a8cb419f").using("btree", table.contestId.asc().nullsLast().op("int4_ops")),
|
||||
index("contest_announcement_created_by_id_469a14ce").using("btree", table.createdById.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.contestId],
|
||||
foreignColumns: [contest.id],
|
||||
name: "contest_announcement_contest_id_a8cb419f_fk_contest_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.createdById],
|
||||
foreignColumns: [user.id],
|
||||
name: "contest_announcement_created_by_id_469a14ce_fk_user_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const flowchartSubmission = pgTable("flowchart_submission", {
|
||||
id: text().primaryKey().notNull(),
|
||||
mermaidCode: text("mermaid_code").notNull(),
|
||||
flowchartData: jsonb("flowchart_data").notNull(),
|
||||
status: integer().notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
aiScore: doublePrecision("ai_score"),
|
||||
aiGrade: varchar("ai_grade", { length: 10 }),
|
||||
aiFeedback: text("ai_feedback"),
|
||||
aiSuggestions: text("ai_suggestions"),
|
||||
aiCriteriaDetails: jsonb("ai_criteria_details").notNull(),
|
||||
aiProvider: varchar("ai_provider", { length: 50 }).notNull(),
|
||||
aiModel: varchar("ai_model", { length: 50 }).notNull(),
|
||||
processingTime: doublePrecision("processing_time"),
|
||||
evaluationTime: timestamp("evaluation_time", { withTimezone: true, mode: 'string' }),
|
||||
problemId: integer("problem_id").notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
}, (table) => [
|
||||
index("flowchart_problem_time_idx").using("btree", table.problemId.asc().nullsLast().op("int4_ops"), table.createTime.asc().nullsLast().op("int4_ops")),
|
||||
index("flowchart_status_idx").using("btree", table.status.asc().nullsLast().op("int4_ops")),
|
||||
index("flowchart_submission_id_0dbfc4f9_like").using("btree", table.id.asc().nullsLast().op("text_pattern_ops")),
|
||||
index("flowchart_submission_problem_id_8551edbf").using("btree", table.problemId.asc().nullsLast().op("int4_ops")),
|
||||
index("flowchart_submission_user_id_225c83e8").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
index("flowchart_user_time_idx").using("btree", table.userId.asc().nullsLast().op("int4_ops"), table.createTime.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.problemId],
|
||||
foreignColumns: [problem.id],
|
||||
name: "flowchart_submission_problem_id_8551edbf_fk_problem_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "flowchart_submission_user_id_225c83e8_fk_user_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const message = pgTable("message", {
|
||||
id: integer().primaryKey().generatedByDefaultAsIdentity({ name: "message_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
message: text().notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
recipientId: integer("recipient_id").notNull(),
|
||||
senderId: integer("sender_id").notNull(),
|
||||
submissionId: text("submission_id").notNull(),
|
||||
}, (table) => [
|
||||
index("message_recipient_id_2aa5dd76").using("btree", table.recipientId.asc().nullsLast().op("int4_ops")),
|
||||
index("message_recipient_time_idx").using("btree", table.recipientId.asc().nullsLast().op("timestamptz_ops"), table.createTime.asc().nullsLast().op("int4_ops")),
|
||||
index("message_sender_id_a2a2e825").using("btree", table.senderId.asc().nullsLast().op("int4_ops")),
|
||||
index("message_submission_id_2fdf8a47").using("btree", table.submissionId.asc().nullsLast().op("text_ops")),
|
||||
index("message_submission_id_2fdf8a47_like").using("btree", table.submissionId.asc().nullsLast().op("text_pattern_ops")),
|
||||
foreignKey({
|
||||
columns: [table.recipientId],
|
||||
foreignColumns: [user.id],
|
||||
name: "message_recipient_id_2aa5dd76_fk_user_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.senderId],
|
||||
foreignColumns: [user.id],
|
||||
name: "message_sender_id_a2a2e825_fk_user_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.submissionId],
|
||||
foreignColumns: [submission.id],
|
||||
name: "message_submission_id_2fdf8a47_fk_submission_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const judgeServer = pgTable("judge_server", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
hostname: text().notNull(),
|
||||
ip: text(),
|
||||
judgerVersion: text("judger_version").notNull(),
|
||||
cpuCore: integer("cpu_core").notNull(),
|
||||
memoryUsage: doublePrecision("memory_usage").notNull(),
|
||||
cpuUsage: doublePrecision("cpu_usage").notNull(),
|
||||
lastHeartbeat: timestamp("last_heartbeat", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
taskNumber: integer("task_number").notNull(),
|
||||
serviceUrl: text("service_url"),
|
||||
isDisabled: boolean("is_disabled").notNull(),
|
||||
});
|
||||
|
||||
export const exercise = pgTable("exercise", {
|
||||
id: integer().primaryKey().generatedByDefaultAsIdentity({ name: "exercise_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
type: varchar({ length: 16 }).notNull(),
|
||||
data: jsonb().notNull(),
|
||||
order: integer().notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
tutorialId: integer("tutorial_id").notNull(),
|
||||
}, (table) => [
|
||||
index("exercise_tutorial_id_6fd04055").using("btree", table.tutorialId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.tutorialId],
|
||||
foreignColumns: [tutorial.id],
|
||||
name: "exercise_tutorial_id_6fd04055_fk_tutorial_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const optionsSysoptions = pgTable("options_sysoptions", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
key: text().notNull(),
|
||||
value: jsonb().notNull(),
|
||||
}, (table) => [
|
||||
unique("options_sysoptions_key_key").on(table.key),
|
||||
]);
|
||||
|
||||
export const problemset = pgTable("problemset", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "problemset_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
title: text().notNull(),
|
||||
description: text().notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
lastUpdateTime: timestamp("last_update_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
visible: boolean().notNull(),
|
||||
difficulty: text().notNull(),
|
||||
status: text().notNull(),
|
||||
createdById: integer("created_by_id").notNull(),
|
||||
endTime: timestamp("end_time", { withTimezone: true, mode: 'string' }),
|
||||
}, (table) => [
|
||||
index("problemset_created_by_id_01b5197f").using("btree", table.createdById.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.createdById],
|
||||
foreignColumns: [user.id],
|
||||
name: "problemset_created_by_id_01b5197f_fk_user_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const problemsetProblem = pgTable("problemset_problem", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "problemset_problem_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
order: integer().notNull(),
|
||||
isRequired: boolean("is_required").notNull(),
|
||||
score: integer().notNull(),
|
||||
hint: text(),
|
||||
problemId: integer("problem_id").notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
problemsetId: bigint("problemset_id", { mode: "number" }).notNull(),
|
||||
}, (table) => [
|
||||
index("problemset_problem_problem_id_fff2d686").using("btree", table.problemId.asc().nullsLast().op("int4_ops")),
|
||||
index("problemset_problem_problemset_id_350d17fb").using("btree", table.problemsetId.asc().nullsLast().op("int8_ops")),
|
||||
foreignKey({
|
||||
columns: [table.problemId],
|
||||
foreignColumns: [problem.id],
|
||||
name: "problemset_problem_problem_id_fff2d686_fk_problem_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.problemsetId],
|
||||
foreignColumns: [problemset.id],
|
||||
name: "problemset_problem_problemset_id_350d17fb_fk_problemset_id"
|
||||
}),
|
||||
unique("unique_problemset_problem").on(table.problemId, table.problemsetId),
|
||||
]);
|
||||
|
||||
export const problemsetProgress = pgTable("problemset_progress", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "problemset_progress_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
joinTime: timestamp("join_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
completeTime: timestamp("complete_time", { withTimezone: true, mode: 'string' }),
|
||||
isCompleted: boolean("is_completed").notNull(),
|
||||
progressPercentage: doublePrecision("progress_percentage").notNull(),
|
||||
completedProblemsCount: integer("completed_problems_count").notNull(),
|
||||
totalProblemsCount: integer("total_problems_count").notNull(),
|
||||
totalScore: integer("total_score").notNull(),
|
||||
progressDetail: jsonb("progress_detail").notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
problemsetId: bigint("problemset_id", { mode: "number" }).notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
}, (table) => [
|
||||
index("problemset_progress_problemset_id_20a9632e").using("btree", table.problemsetId.asc().nullsLast().op("int8_ops")),
|
||||
index("problemset_progress_user_id_c8041a80").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.problemsetId],
|
||||
foreignColumns: [problemset.id],
|
||||
name: "problemset_progress_problemset_id_20a9632e_fk_problemset_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "problemset_progress_user_id_c8041a80_fk_user_id"
|
||||
}),
|
||||
unique("unique_problemset_progress_user").on(table.problemsetId, table.userId),
|
||||
]);
|
||||
|
||||
export const problemsetSubmission = pgTable("problemset_submission", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "problemset_submission_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
problemId: integer("problem_id").notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
problemsetId: bigint("problemset_id", { mode: "number" }).notNull(),
|
||||
submissionId: text("submission_id").notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
}, (table) => [
|
||||
index("problemset__problem_1f39fa_idx").using("btree", table.problemsetId.asc().nullsLast().op("int4_ops"), table.userId.asc().nullsLast().op("int4_ops")),
|
||||
index("problemset__problem_22f053_idx").using("btree", table.problemsetId.asc().nullsLast().op("int8_ops"), table.problemId.asc().nullsLast().op("int8_ops")),
|
||||
index("problemset__user_id_2f1501_idx").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
index("problemset_submission_problem_id_5629b105").using("btree", table.problemId.asc().nullsLast().op("int4_ops")),
|
||||
index("problemset_submission_problemset_id_85290e17").using("btree", table.problemsetId.asc().nullsLast().op("int8_ops")),
|
||||
index("problemset_submission_submission_id_78e2b807").using("btree", table.submissionId.asc().nullsLast().op("text_ops")),
|
||||
index("problemset_submission_submission_id_78e2b807_like").using("btree", table.submissionId.asc().nullsLast().op("text_pattern_ops")),
|
||||
index("problemset_submission_user_id_915fc9c6").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.problemId],
|
||||
foreignColumns: [problem.id],
|
||||
name: "problemset_submission_problem_id_5629b105_fk_problem_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.problemsetId],
|
||||
foreignColumns: [problemset.id],
|
||||
name: "problemset_submission_problemset_id_85290e17_fk_problemset_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.submissionId],
|
||||
foreignColumns: [submission.id],
|
||||
name: "problemset_submission_submission_id_78e2b807_fk_submission_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "problemset_submission_user_id_915fc9c6_fk_user_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const reaction = pgTable("reaction", {
|
||||
id: integer().primaryKey().generatedByDefaultAsIdentity({ name: "reaction_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
type: varchar({ length: 20 }).notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
problemId: integer("problem_id").notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
}, (table) => [
|
||||
index("reaction_problem_id_a7f3b9f3").using("btree", table.problemId.asc().nullsLast().op("int4_ops")),
|
||||
index("reaction_problem_type_idx").using("btree", table.problemId.asc().nullsLast().op("int4_ops"), table.type.asc().nullsLast().op("int4_ops")),
|
||||
index("reaction_user_id_cfa7f469").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.problemId],
|
||||
foreignColumns: [problem.id],
|
||||
name: "reaction_problem_id_a7f3b9f3_fk_problem_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "reaction_user_id_cfa7f469_fk_user_id"
|
||||
}),
|
||||
unique("reaction_problem_user_unique").on(table.problemId, table.userId),
|
||||
]);
|
||||
|
||||
export const problem = pgTable("problem", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
title: text().notNull(),
|
||||
description: text().notNull(),
|
||||
inputDescription: text("input_description").notNull(),
|
||||
outputDescription: text("output_description").notNull(),
|
||||
samples: jsonb().notNull(),
|
||||
testCaseId: text("test_case_id").notNull(),
|
||||
testCaseScore: jsonb("test_case_score").notNull(),
|
||||
hint: text(),
|
||||
languages: jsonb().notNull(),
|
||||
template: jsonb().notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
lastUpdateTime: timestamp("last_update_time", { withTimezone: true, mode: 'string' }),
|
||||
timeLimit: integer("time_limit").notNull(),
|
||||
memoryLimit: integer("memory_limit").notNull(),
|
||||
visible: boolean().default(true).notNull(),
|
||||
difficulty: text().notNull(),
|
||||
source: text(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
submissionNumber: bigint("submission_number", { mode: "number" }).default(0).notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
acceptedNumber: bigint("accepted_number", { mode: "number" }).default(0).notNull(),
|
||||
createdById: integer("created_by_id").notNull(),
|
||||
id: text("_id").notNull(),
|
||||
statisticInfo: jsonb("statistic_info").default({}).notNull(),
|
||||
contestId: integer("contest_id"),
|
||||
isPublic: boolean("is_public").default(false).notNull(),
|
||||
shareSubmission: boolean("share_submission").default(false).notNull(),
|
||||
prompt: text(),
|
||||
answers: jsonb(),
|
||||
allowFlowchart: boolean("allow_flowchart").default(false).notNull(),
|
||||
flowchartData: jsonb("flowchart_data").default({}).notNull(),
|
||||
flowchartHint: text("flowchart_hint"),
|
||||
mermaidCode: text("mermaid_code"),
|
||||
showFlowchart: boolean("show_flowchart").default(false).notNull(),
|
||||
astRules: jsonb("ast_rules"),
|
||||
sqlConfig: jsonb("sql_config"),
|
||||
sqlDisplay: jsonb("sql_display"),
|
||||
}, (table) => [
|
||||
index("problem__id_919b1d80").using("btree", table.id.asc().nullsLast().op("text_ops")),
|
||||
index("problem_contest_id_328e013a").using("btree", table.contestId.asc().nullsLast().op("int4_ops")),
|
||||
index("problem_contest_visible_idx").using("btree", table.contestId.asc().nullsLast().op("bool_ops"), table.visible.asc().nullsLast().op("int4_ops")),
|
||||
index("problem_created_by_id_cb362143").using("btree", table.createdById.asc().nullsLast().op("int4_ops")),
|
||||
index("problem_visible_idx").using("btree", table.visible.asc().nullsLast().op("bool_ops")),
|
||||
foreignKey({
|
||||
columns: [table.contestId],
|
||||
foreignColumns: [contest.id],
|
||||
name: "problem_contest_id_328e013a_fk_contest_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.createdById],
|
||||
foreignColumns: [user.id],
|
||||
name: "problem_created_by_id_cb362143_fk_user_id"
|
||||
}),
|
||||
unique("unique_problem_id_contest").on(table.id, table.contestId),
|
||||
]);
|
||||
|
||||
export const problemTags = pgTable("problem_tags", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
problemId: integer("problem_id").notNull(),
|
||||
problemtagId: integer("problemtag_id").notNull(),
|
||||
}, (table) => [
|
||||
index("problem_tags_problem_id_866ecb8d").using("btree", table.problemId.asc().nullsLast().op("int4_ops")),
|
||||
index("problem_tags_problemtag_id_72d20571").using("btree", table.problemtagId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.problemId],
|
||||
foreignColumns: [problem.id],
|
||||
name: "problem_tags_problem_id_866ecb8d_fk_problem_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.problemtagId],
|
||||
foreignColumns: [problemTag.id],
|
||||
name: "problem_tags_problemtag_id_72d20571_fk_problem_tag_id"
|
||||
}),
|
||||
unique("problem_tags_problem_id_problemtag_id_318459d1_uniq").on(table.problemId, table.problemtagId),
|
||||
]);
|
||||
|
||||
export const problemTag = pgTable("problem_tag", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
name: text().notNull(),
|
||||
}, (table) => [
|
||||
uniqueIndex("problem_tag_name_ci_unique").using("btree", sql`lower(name)`),
|
||||
]);
|
||||
|
||||
export const submission = pgTable("submission", {
|
||||
id: text().primaryKey().notNull(),
|
||||
contestId: integer("contest_id"),
|
||||
problemId: integer("problem_id").notNull(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
code: text().notNull(),
|
||||
result: integer().default(6).notNull(),
|
||||
info: jsonb().default({}).notNull(),
|
||||
language: text().notNull(),
|
||||
shared: boolean().default(false).notNull(),
|
||||
statisticInfo: jsonb("statistic_info").default({}).notNull(),
|
||||
username: text().notNull(),
|
||||
ip: text(),
|
||||
}, (table) => [
|
||||
index("contest_create_time_idx").using("btree", table.contestId.asc().nullsLast().op("timestamptz_ops"), table.createTime.desc().nullsFirst().op("int4_ops")),
|
||||
index("problem_user_idx").using("btree", table.problemId.asc().nullsLast().op("int4_ops"), table.userId.asc().nullsLast().op("int4_ops")),
|
||||
index("submission_contest_id_775716d5").using("btree", table.contestId.asc().nullsLast().op("int4_ops")),
|
||||
index("submission_problem_id_76847b55").using("btree", table.problemId.asc().nullsLast().op("int4_ops")),
|
||||
index("submission_result_37e2f67a").using("btree", table.result.asc().nullsLast().op("int4_ops")),
|
||||
index("submission_user_id_3779a8c1").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
index("user_create_time_idx").using("btree", table.userId.asc().nullsLast().op("int4_ops"), table.createTime.asc().nullsLast().op("timestamptz_ops")),
|
||||
foreignKey({
|
||||
columns: [table.contestId],
|
||||
foreignColumns: [contest.id],
|
||||
name: "submission_contest_id_775716d5_fk_contest_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.problemId],
|
||||
foreignColumns: [problem.id],
|
||||
name: "submission_problem_id_76847b55_fk_problem_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const tutorial = pgTable("tutorial", {
|
||||
id: integer().primaryKey().generatedByDefaultAsIdentity({ name: "tutorial_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
title: varchar({ length: 128 }).notNull(),
|
||||
content: text().notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
isPublic: boolean("is_public").notNull(),
|
||||
order: integer().notNull(),
|
||||
createdById: integer("created_by_id").notNull(),
|
||||
code: text(),
|
||||
type: varchar({ length: 10 }).notNull(),
|
||||
}, (table) => [
|
||||
index("tutorial_created_by_id_07973cab").using("btree", table.createdById.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.createdById],
|
||||
foreignColumns: [user.id],
|
||||
name: "tutorial_created_by_id_07973cab_fk_user_id"
|
||||
}),
|
||||
]);
|
||||
|
||||
export const userStat = pgTable("user_stat", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "user_stat_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
metrics: jsonb().default({}).notNull(),
|
||||
updateTime: timestamp("update_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
}, (table) => [
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "user_stat_user_id_73337fc0_fk_user_id"
|
||||
}),
|
||||
unique("user_stat_user_id_key").on(table.userId),
|
||||
]);
|
||||
|
||||
export const userAchievement = pgTable("user_achievement", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "user_achievement_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
unlockTime: timestamp("unlock_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
backfilled: boolean().default(false).notNull(),
|
||||
notified: boolean().default(false).notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
achievementId: bigint("achievement_id", { mode: "number" }).notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
}, (table) => [
|
||||
index("user_achievement_achievement_id_29db600d").using("btree", table.achievementId.asc().nullsLast().op("int8_ops")),
|
||||
index("user_achievement_user_id_b8ec7d6a").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
index("user_achv_notified_idx").using("btree", table.userId.asc().nullsLast().op("int4_ops"), table.notified.asc().nullsLast().op("bool_ops")),
|
||||
index("user_achv_time_idx").using("btree", table.userId.asc().nullsLast().op("int4_ops"), table.unlockTime.desc().nullsFirst().op("timestamptz_ops")),
|
||||
foreignKey({
|
||||
columns: [table.achievementId],
|
||||
foreignColumns: [achievement.id],
|
||||
name: "user_achievement_achievement_id_29db600d_fk_achievement_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "user_achievement_user_id_b8ec7d6a_fk_user_id"
|
||||
}),
|
||||
unique("unique_user_achievement").on(table.achievementId, table.userId),
|
||||
]);
|
||||
|
||||
export const userBadge = pgTable("user_badge", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "user_badge_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
earnedTime: timestamp("earned_time", { withTimezone: true, mode: 'string' }).notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
badgeId: bigint("badge_id", { mode: "number" }).notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
}, (table) => [
|
||||
index("user_badge_badge_id_92a983e9").using("btree", table.badgeId.asc().nullsLast().op("int8_ops")),
|
||||
index("user_badge_user_id_a286d718").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.badgeId],
|
||||
foreignColumns: [problemsetBadge.id],
|
||||
name: "user_badge_badge_id_92a983e9_fk_problemset_badge_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "user_badge_user_id_a286d718_fk_user_id"
|
||||
}),
|
||||
unique("unique_user_badge").on(table.badgeId, table.userId),
|
||||
]);
|
||||
|
||||
export const userProfile = pgTable("user_profile", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
acmProblemsStatus: jsonb("acm_problems_status").default({}).notNull(),
|
||||
avatar: text().notNull(),
|
||||
blog: varchar({ length: 200 }),
|
||||
mood: text(),
|
||||
acceptedNumber: integer("accepted_number").default(0).notNull(),
|
||||
submissionNumber: integer("submission_number").default(0).notNull(),
|
||||
github: text(),
|
||||
school: text(),
|
||||
major: text(),
|
||||
userId: integer("user_id").notNull(),
|
||||
realName: text("real_name"),
|
||||
language: text(),
|
||||
}, (table) => [
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "user_profile_user_id_8fdce8e2_fk_user_id"
|
||||
}),
|
||||
unique("user_profile_user_id_key").on(table.userId),
|
||||
]);
|
||||
|
||||
export const acmContestRank = pgTable("acm_contest_rank", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
submissionNumber: integer("submission_number").default(0).notNull(),
|
||||
acceptedNumber: integer("accepted_number").default(0).notNull(),
|
||||
totalTime: integer("total_time").default(0).notNull(),
|
||||
submissionInfo: jsonb("submission_info").default({}).notNull(),
|
||||
contestId: integer("contest_id").notNull(),
|
||||
userId: integer("user_id").notNull(),
|
||||
}, (table) => [
|
||||
index("acm_contest_rank_contest_id_21030ccd").using("btree", table.contestId.asc().nullsLast().op("int4_ops")),
|
||||
index("acm_contest_rank_user_id_40391ab2").using("btree", table.userId.asc().nullsLast().op("int4_ops")),
|
||||
index("acm_rank_contest_user_idx").using("btree", table.contestId.asc().nullsLast().op("int4_ops"), table.userId.asc().nullsLast().op("int4_ops")),
|
||||
index("acm_rank_order_idx").using("btree", table.contestId.asc().nullsLast().op("int4_ops"), table.acceptedNumber.asc().nullsLast().op("int4_ops"), table.totalTime.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.contestId],
|
||||
foreignColumns: [contest.id],
|
||||
name: "acm_contest_rank_contest_id_21030ccd_fk_contest_id"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [user.id],
|
||||
name: "acm_contest_rank_user_id_40391ab2_fk_user_id"
|
||||
}),
|
||||
unique("unique_acm_rank_user_contest").on(table.contestId, table.userId),
|
||||
]);
|
||||
|
||||
export const user = pgTable("user", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
password: varchar({ length: 128 }).notNull(),
|
||||
lastLogin: timestamp("last_login", { withTimezone: true, mode: 'string' }),
|
||||
username: text().notNull(),
|
||||
email: text(),
|
||||
createTime: timestamp("create_time", { withTimezone: true, mode: 'string' }),
|
||||
adminType: text("admin_type").notNull(),
|
||||
authToken: text("auth_token"),
|
||||
openApi: boolean("open_api").default(false).notNull(),
|
||||
openApiAppkey: text("open_api_appkey"),
|
||||
isDisabled: boolean("is_disabled").default(false).notNull(),
|
||||
problemPermission: text("problem_permission").notNull(),
|
||||
sessionKeys: jsonb("session_keys").default([]).notNull(),
|
||||
rawPassword: varchar("raw_password", { length: 20 }),
|
||||
className: text("class_name"),
|
||||
}, (table) => [
|
||||
unique("user_username_key").on(table.username),
|
||||
]);
|
||||
|
||||
export const problemsetBadge = pgTable("problemset_badge", {
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "problemset_badge_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
|
||||
name: text().notNull(),
|
||||
description: text().notNull(),
|
||||
icon: text().notNull(),
|
||||
conditionType: text("condition_type").notNull(),
|
||||
conditionValue: integer("condition_value").notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
problemsetId: bigint("problemset_id", { mode: "number" }).notNull(),
|
||||
}, (table) => [
|
||||
index("problemset_badge_problemset_id_6cb6c74f").using("btree", table.problemsetId.asc().nullsLast().op("int8_ops")),
|
||||
foreignKey({
|
||||
columns: [table.problemsetId],
|
||||
foreignColumns: [problemset.id],
|
||||
name: "problemset_badge_problemset_id_6cb6c74f_fk_problemset_id"
|
||||
}),
|
||||
]);
|
||||
4
apps/api/tsconfig.json
Normal file
4
apps/api/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["src", "drizzle.config.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user