0000_crazy_gateway.sql 原本是 drizzle-kit pull 的产物,整份被 /* */ 包着、 可执行语句 0 条,所以任何新库的结构都只能先手工 psql 灌一遍 schema.sql 再打基线。 现在它的内容由 docs/specs/schema.sql(2026-08-07 的生产 pg_dump --schema-only) 机械转换而来:去掉 psql 专有指令 12 条、去掉 7 张 Django 遗留表及其索引外键 41 条, 保留 212 条语句、顺序不动。转换脚本入库在 docs/spikes/。 不含 Django 那 7 张表,是因为 meta/0000_snapshot.json 从来就没有它们(pull 当时 tablesFilter 滤掉了),不建它们才和快照一致;0002 那串 DROP ... IF EXISTS 在新库上 空转、在生产库上真删,两边跑同一串迁移落点相同。 改 0000 对生产库没有影响:migrator 只比 created_at、从不校验 hash,而生产库那行 baseline-0000-faked 早把它挡在门外了。 migrate.ts 配套:空库直接从 0000 建起(并自建 drizzle 记账表——原来这步由 drizzle 的 migrate() 顺手做掉);自举时不触发破坏性闸门,因为空库上没有数据可丢,拦下来只会逼 每个新环境都带一次 OJ2_ALLOW_DESTRUCTIVE,把这道闸训练成习惯动作。「有表但没基线」 仍然 exit 3。 验证:空库自举出来的结构,和「灌 schema.sql + 打基线 + 跑迁移」这条老路子跑出来的 结构,pg_dump --schema-only 逐字节一致(734 行,零差异)。 转换时踩到两个坑,都写进注释了:注释里不能出现 statement-breakpoint 的字面量 (readMigrationFiles 纯文本切分,会把注释从中间切开);过滤 Django 对象要看 public.X 形式的对象引用,不能扫语句字样——user 表有一列叫 auth_token。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
967 lines
39 KiB
SQL
967 lines
39 KiB
SQL
-- OJ2 的基线迁移:把一个空库建成新后端要的结构。
|
||
--
|
||
-- 这份文件**不是** `drizzle-kit generate` 的产物,也不该由它重新生成。原本这里是
|
||
-- `drizzle-kit pull` 吐出来的东西,整份被 /* */ 包着、一条可执行语句都没有,于是
|
||
-- 「空库没法靠迁移自举」——新环境、演练、别人接手,都得先手工 psql 灌一遍 schema.sql。
|
||
--
|
||
-- 现在的内容由 `docs/specs/schema.sql`(生产库 2026-08-07 的 pg_dump --schema-only)
|
||
-- 机械转换而来:去掉 psql 专有指令(\restrict / SET / set_config)、去掉 7 张 Django
|
||
-- 遗留表及其索引与外键,其余原样保留、顺序不动,语句之间插上 drizzle 的分隔标记。
|
||
-- 转换脚本:`docs/spikes/build-baseline-migration.ts`。
|
||
--
|
||
-- 注意:那个分隔标记是纯文本切分,`readMigrationFiles` 不管它出现在哪里 —— 写进注释里
|
||
-- 一样会把文件切开。所以本文件的注释里不要出现它的字面量(我踩过一次,报错是
|
||
-- 「syntax error at or near "。"」,因为注释被从中间切断了)。
|
||
--
|
||
-- 为什么不含 Django 那 7 张表:`meta/0000_snapshot.json` 从来就没有它们(pull 当时用
|
||
-- tablesFilter 滤掉了),所以不建它们才和快照一致。0002 那条 DROP 全带 IF EXISTS,
|
||
-- 在新库上是空转,在生产库上才真删——两边跑同一串迁移,落点相同。
|
||
--
|
||
-- **改 schema 不要动这个文件**,走 `bun run db:generate` 生成新的迁移。
|
||
-- 生产库早已把 0000 标记成已执行(migrator 只比 created_at、不校验 hash),
|
||
-- 所以这份内容的任何改动都不会在生产库上重放。
|
||
|
||
CREATE TABLE public.achievement (
|
||
id bigint NOT NULL,
|
||
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
|
||
ALTER TABLE public.achievement ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.achievement_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.acm_contest_rank (
|
||
id integer 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
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE SEQUENCE public.acm_contest_rank_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.acm_contest_rank_id_seq OWNED BY public.acm_contest_rank.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.ai_analysis (
|
||
id bigint NOT NULL,
|
||
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
|
||
ALTER TABLE public.ai_analysis ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.ai_analysis_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.announcement (
|
||
id integer 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 SEQUENCE public.announcement_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.announcement_id_seq OWNED BY public.announcement.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.contest (
|
||
id integer 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 public.contest_announcement (
|
||
id integer 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 SEQUENCE public.contest_announcement_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.contest_announcement_id_seq OWNED BY public.contest_announcement.id;
|
||
--> statement-breakpoint
|
||
CREATE SEQUENCE public.contest_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.contest_id_seq OWNED BY public.contest.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.exercise (
|
||
id integer NOT NULL,
|
||
type character varying(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
|
||
ALTER TABLE public.exercise ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.exercise_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.flowchart_submission (
|
||
id text 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 character varying(10),
|
||
ai_feedback text,
|
||
ai_suggestions text,
|
||
ai_criteria_details jsonb NOT NULL,
|
||
ai_provider character varying(50) NOT NULL,
|
||
ai_model character varying(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 public.judge_server (
|
||
id integer 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 SEQUENCE public.judge_server_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.judge_server_id_seq OWNED BY public.judge_server.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.message (
|
||
id integer NOT NULL,
|
||
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
|
||
ALTER TABLE public.message ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.message_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.options_sysoptions (
|
||
id integer NOT NULL,
|
||
key text NOT NULL,
|
||
value jsonb NOT NULL
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE SEQUENCE public.options_sysoptions_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.options_sysoptions_id_seq OWNED BY public.options_sysoptions.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.problem (
|
||
id integer 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
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE SEQUENCE public.problem_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.problem_id_seq OWNED BY public.problem.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.problem_tag (
|
||
id integer NOT NULL,
|
||
name text NOT NULL
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE SEQUENCE public.problem_tag_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.problem_tag_id_seq OWNED BY public.problem_tag.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.problem_tags (
|
||
id integer NOT NULL,
|
||
problem_id integer NOT NULL,
|
||
problemtag_id integer NOT NULL
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE SEQUENCE public.problem_tags_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.problem_tags_id_seq OWNED BY public.problem_tags.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.problemset (
|
||
id bigint NOT NULL,
|
||
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 public.problemset_badge (
|
||
id bigint NOT NULL,
|
||
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 public.problemset_badge ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.problemset_badge_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.problemset ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.problemset_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.problemset_problem (
|
||
id bigint NOT NULL,
|
||
"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
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.problemset_problem ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.problemset_problem_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.problemset_progress (
|
||
id bigint NOT NULL,
|
||
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
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.problemset_progress ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.problemset_progress_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.problemset_submission (
|
||
id bigint NOT NULL,
|
||
problem_id integer NOT NULL,
|
||
problemset_id bigint NOT NULL,
|
||
submission_id text NOT NULL,
|
||
user_id integer NOT NULL
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.problemset_submission ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.problemset_submission_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.reaction (
|
||
id integer NOT NULL,
|
||
type character varying(20) NOT NULL,
|
||
create_time timestamp with time zone NOT NULL,
|
||
problem_id integer NOT NULL,
|
||
user_id integer NOT NULL
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.reaction ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.reaction_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.submission (
|
||
id text 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 public.tutorial (
|
||
id integer NOT NULL,
|
||
title character varying(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 character varying(10) NOT NULL
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.tutorial ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.tutorial_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public."user" (
|
||
id integer NOT NULL,
|
||
password character varying(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 character varying(20),
|
||
class_name text
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.user_achievement (
|
||
id bigint NOT NULL,
|
||
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
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.user_achievement ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.user_achievement_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.user_badge (
|
||
id bigint NOT NULL,
|
||
earned_time timestamp with time zone NOT NULL,
|
||
badge_id bigint NOT NULL,
|
||
user_id integer NOT NULL
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.user_badge ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.user_badge_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE SEQUENCE public.user_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.user_id_seq OWNED BY public."user".id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.user_profile (
|
||
id integer NOT NULL,
|
||
acm_problems_status jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||
avatar text NOT NULL,
|
||
blog character varying(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
|
||
);
|
||
--> statement-breakpoint
|
||
CREATE SEQUENCE public.user_profile_id_seq
|
||
AS integer
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1;
|
||
--> statement-breakpoint
|
||
ALTER SEQUENCE public.user_profile_id_seq OWNED BY public.user_profile.id;
|
||
--> statement-breakpoint
|
||
CREATE TABLE public.user_stat (
|
||
id bigint NOT NULL,
|
||
metrics jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||
update_time timestamp with time zone NOT NULL,
|
||
user_id integer NOT NULL
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE public.user_stat ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||
SEQUENCE NAME public.user_stat_id_seq
|
||
START WITH 1
|
||
INCREMENT BY 1
|
||
NO MINVALUE
|
||
NO MAXVALUE
|
||
CACHE 1
|
||
);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.acm_contest_rank ALTER COLUMN id SET DEFAULT nextval('public.acm_contest_rank_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.announcement ALTER COLUMN id SET DEFAULT nextval('public.announcement_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.contest ALTER COLUMN id SET DEFAULT nextval('public.contest_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.contest_announcement ALTER COLUMN id SET DEFAULT nextval('public.contest_announcement_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.judge_server ALTER COLUMN id SET DEFAULT nextval('public.judge_server_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.options_sysoptions ALTER COLUMN id SET DEFAULT nextval('public.options_sysoptions_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem ALTER COLUMN id SET DEFAULT nextval('public.problem_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem_tag ALTER COLUMN id SET DEFAULT nextval('public.problem_tag_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem_tags ALTER COLUMN id SET DEFAULT nextval('public.problem_tags_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public."user" ALTER COLUMN id SET DEFAULT nextval('public.user_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_profile ALTER COLUMN id SET DEFAULT nextval('public.user_profile_id_seq'::regclass);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.achievement
|
||
ADD CONSTRAINT achievement_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.acm_contest_rank
|
||
ADD CONSTRAINT acm_contest_rank_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.ai_analysis
|
||
ADD CONSTRAINT ai_analysis_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.announcement
|
||
ADD CONSTRAINT announcement_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.contest_announcement
|
||
ADD CONSTRAINT contest_announcement_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.contest
|
||
ADD CONSTRAINT contest_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.exercise
|
||
ADD CONSTRAINT exercise_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.flowchart_submission
|
||
ADD CONSTRAINT flowchart_submission_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.judge_server
|
||
ADD CONSTRAINT judge_server_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.message
|
||
ADD CONSTRAINT message_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.options_sysoptions
|
||
ADD CONSTRAINT options_sysoptions_key_key UNIQUE (key);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.options_sysoptions
|
||
ADD CONSTRAINT options_sysoptions_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem
|
||
ADD CONSTRAINT problem_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem_tag
|
||
ADD CONSTRAINT problem_tag_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem_tags
|
||
ADD CONSTRAINT problem_tags_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem_tags
|
||
ADD CONSTRAINT problem_tags_problem_id_problemtag_id_318459d1_uniq UNIQUE (problem_id, problemtag_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_badge
|
||
ADD CONSTRAINT problemset_badge_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset
|
||
ADD CONSTRAINT problemset_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_problem
|
||
ADD CONSTRAINT problemset_problem_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_progress
|
||
ADD CONSTRAINT problemset_progress_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_submission
|
||
ADD CONSTRAINT problemset_submission_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.reaction
|
||
ADD CONSTRAINT reaction_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.reaction
|
||
ADD CONSTRAINT reaction_problem_user_unique UNIQUE (problem_id, user_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.submission
|
||
ADD CONSTRAINT submission_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.tutorial
|
||
ADD CONSTRAINT tutorial_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.acm_contest_rank
|
||
ADD CONSTRAINT unique_acm_rank_user_contest UNIQUE (user_id, contest_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem
|
||
ADD CONSTRAINT unique_problem_id_contest UNIQUE (_id, contest_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_problem
|
||
ADD CONSTRAINT unique_problemset_problem UNIQUE (problemset_id, problem_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_progress
|
||
ADD CONSTRAINT unique_problemset_progress_user UNIQUE (problemset_id, user_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_achievement
|
||
ADD CONSTRAINT unique_user_achievement UNIQUE (user_id, achievement_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_badge
|
||
ADD CONSTRAINT unique_user_badge UNIQUE (user_id, badge_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_achievement
|
||
ADD CONSTRAINT user_achievement_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_badge
|
||
ADD CONSTRAINT user_badge_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public."user"
|
||
ADD CONSTRAINT user_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_profile
|
||
ADD CONSTRAINT user_profile_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_profile
|
||
ADD CONSTRAINT user_profile_user_id_key UNIQUE (user_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_stat
|
||
ADD CONSTRAINT user_stat_pkey PRIMARY KEY (id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_stat
|
||
ADD CONSTRAINT user_stat_user_id_key UNIQUE (user_id);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public."user"
|
||
ADD CONSTRAINT user_username_key UNIQUE (username);
|
||
--> statement-breakpoint
|
||
CREATE INDEX acm_contest_rank_contest_id_21030ccd ON public.acm_contest_rank USING btree (contest_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX acm_contest_rank_user_id_40391ab2 ON public.acm_contest_rank USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX acm_rank_contest_user_idx ON public.acm_contest_rank USING btree (contest_id, user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX acm_rank_order_idx ON public.acm_contest_rank USING btree (contest_id, accepted_number, total_time);
|
||
--> statement-breakpoint
|
||
CREATE INDEX ai_analysis_user_id_3aa23011 ON public.ai_analysis USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX announcement_created_by_id_359ccf50 ON public.announcement USING btree (created_by_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX announcement_list_idx ON public.announcement USING btree (visible, top DESC, create_time DESC);
|
||
--> statement-breakpoint
|
||
CREATE INDEX contest_announcement_contest_id_a8cb419f ON public.contest_announcement USING btree (contest_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX contest_announcement_created_by_id_469a14ce ON public.contest_announcement USING btree (created_by_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX contest_create_time_idx ON public.submission USING btree (contest_id, create_time DESC);
|
||
--> statement-breakpoint
|
||
CREATE INDEX contest_created_by_id_a763ca7e ON public.contest USING btree (created_by_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX exercise_tutorial_id_6fd04055 ON public.exercise USING btree (tutorial_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX flowchart_problem_time_idx ON public.flowchart_submission USING btree (problem_id, create_time);
|
||
--> statement-breakpoint
|
||
CREATE INDEX flowchart_status_idx ON public.flowchart_submission USING btree (status);
|
||
--> statement-breakpoint
|
||
CREATE INDEX flowchart_submission_id_0dbfc4f9_like ON public.flowchart_submission USING btree (id text_pattern_ops);
|
||
--> statement-breakpoint
|
||
CREATE INDEX flowchart_submission_problem_id_8551edbf ON public.flowchart_submission USING btree (problem_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX flowchart_submission_user_id_225c83e8 ON public.flowchart_submission USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX flowchart_user_time_idx ON public.flowchart_submission USING btree (user_id, create_time);
|
||
--> statement-breakpoint
|
||
CREATE INDEX message_recipient_id_2aa5dd76 ON public.message USING btree (recipient_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX message_recipient_time_idx ON public.message USING btree (recipient_id, create_time);
|
||
--> statement-breakpoint
|
||
CREATE INDEX message_sender_id_a2a2e825 ON public.message USING btree (sender_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX message_submission_id_2fdf8a47 ON public.message USING btree (submission_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX message_submission_id_2fdf8a47_like ON public.message USING btree (submission_id text_pattern_ops);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problem__id_919b1d80 ON public.problem USING btree (_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problem_contest_id_328e013a ON public.problem USING btree (contest_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problem_contest_visible_idx ON public.problem USING btree (contest_id, visible);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problem_created_by_id_cb362143 ON public.problem USING btree (created_by_id);
|
||
--> statement-breakpoint
|
||
CREATE UNIQUE INDEX problem_tag_name_ci_unique ON public.problem_tag USING btree (lower(name));
|
||
--> statement-breakpoint
|
||
CREATE INDEX problem_tags_problem_id_866ecb8d ON public.problem_tags USING btree (problem_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problem_tags_problemtag_id_72d20571 ON public.problem_tags USING btree (problemtag_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problem_user_idx ON public.submission USING btree (problem_id, user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problem_visible_idx ON public.problem USING btree (visible);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset__problem_1f39fa_idx ON public.problemset_submission USING btree (problemset_id, user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset__problem_22f053_idx ON public.problemset_submission USING btree (problemset_id, problem_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset__user_id_2f1501_idx ON public.problemset_submission USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_badge_problemset_id_6cb6c74f ON public.problemset_badge USING btree (problemset_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_created_by_id_01b5197f ON public.problemset USING btree (created_by_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_problem_problem_id_fff2d686 ON public.problemset_problem USING btree (problem_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_problem_problemset_id_350d17fb ON public.problemset_problem USING btree (problemset_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_progress_problemset_id_20a9632e ON public.problemset_progress USING btree (problemset_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_progress_user_id_c8041a80 ON public.problemset_progress USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_submission_problem_id_5629b105 ON public.problemset_submission USING btree (problem_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_submission_problemset_id_85290e17 ON public.problemset_submission USING btree (problemset_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_submission_submission_id_78e2b807 ON public.problemset_submission USING btree (submission_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_submission_submission_id_78e2b807_like ON public.problemset_submission USING btree (submission_id text_pattern_ops);
|
||
--> statement-breakpoint
|
||
CREATE INDEX problemset_submission_user_id_915fc9c6 ON public.problemset_submission USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX reaction_problem_id_a7f3b9f3 ON public.reaction USING btree (problem_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX reaction_problem_type_idx ON public.reaction USING btree (problem_id, type);
|
||
--> statement-breakpoint
|
||
CREATE INDEX reaction_user_id_cfa7f469 ON public.reaction USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX submission_contest_id_775716d5 ON public.submission USING btree (contest_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX submission_problem_id_76847b55 ON public.submission USING btree (problem_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX submission_result_37e2f67a ON public.submission USING btree (result);
|
||
--> statement-breakpoint
|
||
CREATE INDEX submission_user_id_3779a8c1 ON public.submission USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX tutorial_created_by_id_07973cab ON public.tutorial USING btree (created_by_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX user_achievement_achievement_id_29db600d ON public.user_achievement USING btree (achievement_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX user_achievement_user_id_b8ec7d6a ON public.user_achievement USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX user_achv_notified_idx ON public.user_achievement USING btree (user_id, notified);
|
||
--> statement-breakpoint
|
||
CREATE INDEX user_achv_time_idx ON public.user_achievement USING btree (user_id, unlock_time DESC);
|
||
--> statement-breakpoint
|
||
CREATE INDEX user_badge_badge_id_92a983e9 ON public.user_badge USING btree (badge_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX user_badge_user_id_a286d718 ON public.user_badge USING btree (user_id);
|
||
--> statement-breakpoint
|
||
CREATE INDEX user_create_time_idx ON public.submission USING btree (user_id, create_time);
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.acm_contest_rank
|
||
ADD CONSTRAINT acm_contest_rank_contest_id_21030ccd_fk_contest_id FOREIGN KEY (contest_id) REFERENCES public.contest(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.acm_contest_rank
|
||
ADD CONSTRAINT acm_contest_rank_user_id_40391ab2_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.ai_analysis
|
||
ADD CONSTRAINT ai_analysis_user_id_3aa23011_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.announcement
|
||
ADD CONSTRAINT announcement_created_by_id_359ccf50_fk_user_id FOREIGN KEY (created_by_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.contest_announcement
|
||
ADD CONSTRAINT contest_announcement_contest_id_a8cb419f_fk_contest_id FOREIGN KEY (contest_id) REFERENCES public.contest(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.contest_announcement
|
||
ADD CONSTRAINT contest_announcement_created_by_id_469a14ce_fk_user_id FOREIGN KEY (created_by_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.contest
|
||
ADD CONSTRAINT contest_created_by_id_a763ca7e_fk_user_id FOREIGN KEY (created_by_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.exercise
|
||
ADD CONSTRAINT exercise_tutorial_id_6fd04055_fk_tutorial_id FOREIGN KEY (tutorial_id) REFERENCES public.tutorial(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.flowchart_submission
|
||
ADD CONSTRAINT flowchart_submission_problem_id_8551edbf_fk_problem_id FOREIGN KEY (problem_id) REFERENCES public.problem(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.flowchart_submission
|
||
ADD CONSTRAINT flowchart_submission_user_id_225c83e8_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.message
|
||
ADD CONSTRAINT message_recipient_id_2aa5dd76_fk_user_id FOREIGN KEY (recipient_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.message
|
||
ADD CONSTRAINT message_sender_id_a2a2e825_fk_user_id FOREIGN KEY (sender_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.message
|
||
ADD CONSTRAINT message_submission_id_2fdf8a47_fk_submission_id FOREIGN KEY (submission_id) REFERENCES public.submission(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem
|
||
ADD CONSTRAINT problem_contest_id_328e013a_fk_contest_id FOREIGN KEY (contest_id) REFERENCES public.contest(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem
|
||
ADD CONSTRAINT problem_created_by_id_cb362143_fk_user_id FOREIGN KEY (created_by_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem_tags
|
||
ADD CONSTRAINT problem_tags_problem_id_866ecb8d_fk_problem_id FOREIGN KEY (problem_id) REFERENCES public.problem(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problem_tags
|
||
ADD CONSTRAINT problem_tags_problemtag_id_72d20571_fk_problem_tag_id FOREIGN KEY (problemtag_id) REFERENCES public.problem_tag(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_badge
|
||
ADD CONSTRAINT problemset_badge_problemset_id_6cb6c74f_fk_problemset_id FOREIGN KEY (problemset_id) REFERENCES public.problemset(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset
|
||
ADD CONSTRAINT problemset_created_by_id_01b5197f_fk_user_id FOREIGN KEY (created_by_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_problem
|
||
ADD CONSTRAINT problemset_problem_problem_id_fff2d686_fk_problem_id FOREIGN KEY (problem_id) REFERENCES public.problem(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_problem
|
||
ADD CONSTRAINT problemset_problem_problemset_id_350d17fb_fk_problemset_id FOREIGN KEY (problemset_id) REFERENCES public.problemset(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_progress
|
||
ADD CONSTRAINT problemset_progress_problemset_id_20a9632e_fk_problemset_id FOREIGN KEY (problemset_id) REFERENCES public.problemset(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_progress
|
||
ADD CONSTRAINT problemset_progress_user_id_c8041a80_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_submission
|
||
ADD CONSTRAINT problemset_submission_problem_id_5629b105_fk_problem_id FOREIGN KEY (problem_id) REFERENCES public.problem(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_submission
|
||
ADD CONSTRAINT problemset_submission_problemset_id_85290e17_fk_problemset_id FOREIGN KEY (problemset_id) REFERENCES public.problemset(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_submission
|
||
ADD CONSTRAINT problemset_submission_submission_id_78e2b807_fk_submission_id FOREIGN KEY (submission_id) REFERENCES public.submission(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.problemset_submission
|
||
ADD CONSTRAINT problemset_submission_user_id_915fc9c6_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.reaction
|
||
ADD CONSTRAINT reaction_problem_id_a7f3b9f3_fk_problem_id FOREIGN KEY (problem_id) REFERENCES public.problem(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.reaction
|
||
ADD CONSTRAINT reaction_user_id_cfa7f469_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.submission
|
||
ADD CONSTRAINT submission_contest_id_775716d5_fk_contest_id FOREIGN KEY (contest_id) REFERENCES public.contest(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.submission
|
||
ADD CONSTRAINT submission_problem_id_76847b55_fk_problem_id FOREIGN KEY (problem_id) REFERENCES public.problem(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.tutorial
|
||
ADD CONSTRAINT tutorial_created_by_id_07973cab_fk_user_id FOREIGN KEY (created_by_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_achievement
|
||
ADD CONSTRAINT user_achievement_achievement_id_29db600d_fk_achievement_id FOREIGN KEY (achievement_id) REFERENCES public.achievement(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_achievement
|
||
ADD CONSTRAINT user_achievement_user_id_b8ec7d6a_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_badge
|
||
ADD CONSTRAINT user_badge_badge_id_92a983e9_fk_problemset_badge_id FOREIGN KEY (badge_id) REFERENCES public.problemset_badge(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_badge
|
||
ADD CONSTRAINT user_badge_user_id_a286d718_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_profile
|
||
ADD CONSTRAINT user_profile_user_id_8fdce8e2_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|
||
--> statement-breakpoint
|
||
ALTER TABLE ONLY public.user_stat
|
||
ADD CONSTRAINT user_stat_user_id_73337fc0_fk_user_id FOREIGN KEY (user_id) REFERENCES public."user"(id) DEFERRABLE INITIALLY DEFERRED;
|