schema.sql 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. --
  2. -- PostgreSQL database dump
  3. --
  4. \restrict ESQ1NFAz6xVH1qNjdPPTbrmPbtepjMOr7SzmqGUWW2SDRd1pbhCctBfDStfCiB2
  5. -- Dumped from database version 16.14 (Debian 16.14-1.pgdg12+1)
  6. -- Dumped by pg_dump version 16.14 (Debian 16.14-1.pgdg12+1)
  7. SET statement_timeout = 0;
  8. SET lock_timeout = 0;
  9. SET idle_in_transaction_session_timeout = 0;
  10. SET client_encoding = 'UTF8';
  11. SET standard_conforming_strings = on;
  12. SELECT pg_catalog.set_config('search_path', '', false);
  13. SET check_function_bodies = false;
  14. SET xmloption = content;
  15. SET client_min_messages = warning;
  16. SET row_security = off;
  17. --
  18. -- Name: vector; Type: EXTENSION; Schema: -; Owner: -
  19. --
  20. CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA public;
  21. --
  22. -- Name: EXTENSION vector; Type: COMMENT; Schema: -; Owner: -
  23. --
  24. COMMENT ON EXTENSION vector IS 'vector data type and ivfflat and hnsw access methods';
  25. SET default_tablespace = '';
  26. SET default_table_access_method = heap;
  27. --
  28. -- Name: answer_records; Type: TABLE; Schema: public; Owner: -
  29. --
  30. CREATE TABLE public.answer_records (
  31. id integer NOT NULL,
  32. user_id integer NOT NULL,
  33. question_id character varying(64) NOT NULL,
  34. user_answer character varying(16) NOT NULL,
  35. is_correct boolean NOT NULL,
  36. study_mode character varying(32) NOT NULL,
  37. created_at timestamp with time zone DEFAULT now() NOT NULL
  38. );
  39. --
  40. -- Name: answer_records_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  41. --
  42. CREATE SEQUENCE public.answer_records_id_seq
  43. AS integer
  44. START WITH 1
  45. INCREMENT BY 1
  46. NO MINVALUE
  47. NO MAXVALUE
  48. CACHE 1;
  49. --
  50. -- Name: answer_records_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  51. --
  52. ALTER SEQUENCE public.answer_records_id_seq OWNED BY public.answer_records.id;
  53. --
  54. -- Name: conversations; Type: TABLE; Schema: public; Owner: -
  55. --
  56. CREATE TABLE public.conversations (
  57. id integer NOT NULL,
  58. conversation_id character varying(64) NOT NULL,
  59. user_id integer,
  60. title character varying(256),
  61. created_at timestamp with time zone DEFAULT now() NOT NULL
  62. );
  63. --
  64. -- Name: conversations_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  65. --
  66. CREATE SEQUENCE public.conversations_id_seq
  67. AS integer
  68. START WITH 1
  69. INCREMENT BY 1
  70. NO MINVALUE
  71. NO MAXVALUE
  72. CACHE 1;
  73. --
  74. -- Name: conversations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  75. --
  76. ALTER SEQUENCE public.conversations_id_seq OWNED BY public.conversations.id;
  77. --
  78. -- Name: drug_chunks; Type: TABLE; Schema: public; Owner: -
  79. --
  80. CREATE TABLE public.drug_chunks (
  81. id integer NOT NULL,
  82. drug_id character varying(64) NOT NULL,
  83. section character varying(64),
  84. content text NOT NULL,
  85. source text,
  86. chunk_index integer NOT NULL,
  87. embedding json,
  88. created_at timestamp with time zone DEFAULT now() NOT NULL,
  89. vec public.vector(1024)
  90. );
  91. --
  92. -- Name: drug_chunks_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  93. --
  94. CREATE SEQUENCE public.drug_chunks_id_seq
  95. AS integer
  96. START WITH 1
  97. INCREMENT BY 1
  98. NO MINVALUE
  99. NO MAXVALUE
  100. CACHE 1;
  101. --
  102. -- Name: drug_chunks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  103. --
  104. ALTER SEQUENCE public.drug_chunks_id_seq OWNED BY public.drug_chunks.id;
  105. --
  106. -- Name: drugs; Type: TABLE; Schema: public; Owner: -
  107. --
  108. CREATE TABLE public.drugs (
  109. id integer NOT NULL,
  110. drug_id character varying(64) NOT NULL,
  111. name character varying(256) NOT NULL,
  112. name_en character varying(256),
  113. pinyin character varying(256),
  114. category character varying(64),
  115. subcategory character varying(128),
  116. approval_number character varying(64),
  117. sections jsonb,
  118. source_version character varying(32),
  119. source_volume character varying(512),
  120. source_page character varying(256),
  121. is_active boolean NOT NULL,
  122. created_at timestamp with time zone DEFAULT now() NOT NULL,
  123. updated_at timestamp with time zone DEFAULT now() NOT NULL
  124. );
  125. --
  126. -- Name: drugs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  127. --
  128. CREATE SEQUENCE public.drugs_id_seq
  129. AS integer
  130. START WITH 1
  131. INCREMENT BY 1
  132. NO MINVALUE
  133. NO MAXVALUE
  134. CACHE 1;
  135. --
  136. -- Name: drugs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  137. --
  138. ALTER SEQUENCE public.drugs_id_seq OWNED BY public.drugs.id;
  139. --
  140. -- Name: knowledge_points; Type: TABLE; Schema: public; Owner: -
  141. --
  142. CREATE TABLE public.knowledge_points (
  143. id integer NOT NULL,
  144. point_id character varying(64) NOT NULL,
  145. subject character varying(64) NOT NULL,
  146. chapter_id character varying(64) NOT NULL,
  147. chapter_name character varying(256) NOT NULL,
  148. title character varying(512) NOT NULL,
  149. content text NOT NULL,
  150. difficulty integer NOT NULL,
  151. frequency character varying(16),
  152. related_drugs jsonb,
  153. source text,
  154. vector_id character varying(128),
  155. created_at timestamp with time zone DEFAULT now() NOT NULL,
  156. updated_at timestamp with time zone DEFAULT now() NOT NULL
  157. );
  158. --
  159. -- Name: knowledge_points_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  160. --
  161. CREATE SEQUENCE public.knowledge_points_id_seq
  162. AS integer
  163. START WITH 1
  164. INCREMENT BY 1
  165. NO MINVALUE
  166. NO MAXVALUE
  167. CACHE 1;
  168. --
  169. -- Name: knowledge_points_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  170. --
  171. ALTER SEQUENCE public.knowledge_points_id_seq OWNED BY public.knowledge_points.id;
  172. --
  173. -- Name: messages; Type: TABLE; Schema: public; Owner: -
  174. --
  175. CREATE TABLE public.messages (
  176. id integer NOT NULL,
  177. conversation_id character varying(64) NOT NULL,
  178. role character varying(32) NOT NULL,
  179. content text NOT NULL,
  180. intent character varying(32),
  181. sources json,
  182. feedback character varying(32),
  183. created_at timestamp with time zone DEFAULT now() NOT NULL
  184. );
  185. --
  186. -- Name: messages_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  187. --
  188. CREATE SEQUENCE public.messages_id_seq
  189. AS integer
  190. START WITH 1
  191. INCREMENT BY 1
  192. NO MINVALUE
  193. NO MAXVALUE
  194. CACHE 1;
  195. --
  196. -- Name: messages_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  197. --
  198. ALTER SEQUENCE public.messages_id_seq OWNED BY public.messages.id;
  199. --
  200. -- Name: questions; Type: TABLE; Schema: public; Owner: -
  201. --
  202. CREATE TABLE public.questions (
  203. id integer NOT NULL,
  204. question_id character varying(64) NOT NULL,
  205. question_type character varying(8) NOT NULL,
  206. subject character varying(64) NOT NULL,
  207. chapter_id character varying(64) NOT NULL,
  208. difficulty integer NOT NULL,
  209. content text NOT NULL,
  210. options jsonb NOT NULL,
  211. answer character varying(16) NOT NULL,
  212. explanation text NOT NULL,
  213. knowledge_point_ids jsonb,
  214. source text,
  215. frequency character varying(16),
  216. audited boolean NOT NULL,
  217. correct_count integer NOT NULL,
  218. attempt_count integer NOT NULL,
  219. created_at timestamp with time zone DEFAULT now() NOT NULL
  220. );
  221. --
  222. -- Name: questions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  223. --
  224. CREATE SEQUENCE public.questions_id_seq
  225. AS integer
  226. START WITH 1
  227. INCREMENT BY 1
  228. NO MINVALUE
  229. NO MAXVALUE
  230. CACHE 1;
  231. --
  232. -- Name: questions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  233. --
  234. ALTER SEQUENCE public.questions_id_seq OWNED BY public.questions.id;
  235. --
  236. -- Name: user_progress; Type: TABLE; Schema: public; Owner: -
  237. --
  238. CREATE TABLE public.user_progress (
  239. id integer NOT NULL,
  240. user_id integer NOT NULL,
  241. subject character varying(64),
  242. chapter_id character varying(64),
  243. knowledge_point_id character varying(64),
  244. questions_answered integer NOT NULL,
  245. questions_correct integer NOT NULL,
  246. study_seconds integer NOT NULL,
  247. last_study_at timestamp with time zone,
  248. created_at timestamp with time zone DEFAULT now() NOT NULL,
  249. updated_at timestamp with time zone DEFAULT now() NOT NULL
  250. );
  251. --
  252. -- Name: user_progress_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  253. --
  254. CREATE SEQUENCE public.user_progress_id_seq
  255. AS integer
  256. START WITH 1
  257. INCREMENT BY 1
  258. NO MINVALUE
  259. NO MAXVALUE
  260. CACHE 1;
  261. --
  262. -- Name: user_progress_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  263. --
  264. ALTER SEQUENCE public.user_progress_id_seq OWNED BY public.user_progress.id;
  265. --
  266. -- Name: users; Type: TABLE; Schema: public; Owner: -
  267. --
  268. CREATE TABLE public.users (
  269. id integer NOT NULL,
  270. openid character varying(128) NOT NULL,
  271. nickname character varying(128),
  272. avatar_url character varying(512),
  273. role character varying(32) NOT NULL,
  274. created_at timestamp with time zone DEFAULT now() NOT NULL,
  275. updated_at timestamp with time zone DEFAULT now() NOT NULL
  276. );
  277. --
  278. -- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  279. --
  280. CREATE SEQUENCE public.users_id_seq
  281. AS integer
  282. START WITH 1
  283. INCREMENT BY 1
  284. NO MINVALUE
  285. NO MAXVALUE
  286. CACHE 1;
  287. --
  288. -- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  289. --
  290. ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
  291. --
  292. -- Name: answer_records id; Type: DEFAULT; Schema: public; Owner: -
  293. --
  294. ALTER TABLE ONLY public.answer_records ALTER COLUMN id SET DEFAULT nextval('public.answer_records_id_seq'::regclass);
  295. --
  296. -- Name: conversations id; Type: DEFAULT; Schema: public; Owner: -
  297. --
  298. ALTER TABLE ONLY public.conversations ALTER COLUMN id SET DEFAULT nextval('public.conversations_id_seq'::regclass);
  299. --
  300. -- Name: drug_chunks id; Type: DEFAULT; Schema: public; Owner: -
  301. --
  302. ALTER TABLE ONLY public.drug_chunks ALTER COLUMN id SET DEFAULT nextval('public.drug_chunks_id_seq'::regclass);
  303. --
  304. -- Name: drugs id; Type: DEFAULT; Schema: public; Owner: -
  305. --
  306. ALTER TABLE ONLY public.drugs ALTER COLUMN id SET DEFAULT nextval('public.drugs_id_seq'::regclass);
  307. --
  308. -- Name: knowledge_points id; Type: DEFAULT; Schema: public; Owner: -
  309. --
  310. ALTER TABLE ONLY public.knowledge_points ALTER COLUMN id SET DEFAULT nextval('public.knowledge_points_id_seq'::regclass);
  311. --
  312. -- Name: messages id; Type: DEFAULT; Schema: public; Owner: -
  313. --
  314. ALTER TABLE ONLY public.messages ALTER COLUMN id SET DEFAULT nextval('public.messages_id_seq'::regclass);
  315. --
  316. -- Name: questions id; Type: DEFAULT; Schema: public; Owner: -
  317. --
  318. ALTER TABLE ONLY public.questions ALTER COLUMN id SET DEFAULT nextval('public.questions_id_seq'::regclass);
  319. --
  320. -- Name: user_progress id; Type: DEFAULT; Schema: public; Owner: -
  321. --
  322. ALTER TABLE ONLY public.user_progress ALTER COLUMN id SET DEFAULT nextval('public.user_progress_id_seq'::regclass);
  323. --
  324. -- Name: users id; Type: DEFAULT; Schema: public; Owner: -
  325. --
  326. ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
  327. --
  328. -- Name: answer_records answer_records_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  329. --
  330. ALTER TABLE ONLY public.answer_records
  331. ADD CONSTRAINT answer_records_pkey PRIMARY KEY (id);
  332. --
  333. -- Name: conversations conversations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  334. --
  335. ALTER TABLE ONLY public.conversations
  336. ADD CONSTRAINT conversations_pkey PRIMARY KEY (id);
  337. --
  338. -- Name: drug_chunks drug_chunks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  339. --
  340. ALTER TABLE ONLY public.drug_chunks
  341. ADD CONSTRAINT drug_chunks_pkey PRIMARY KEY (id);
  342. --
  343. -- Name: drugs drugs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  344. --
  345. ALTER TABLE ONLY public.drugs
  346. ADD CONSTRAINT drugs_pkey PRIMARY KEY (id);
  347. --
  348. -- Name: knowledge_points knowledge_points_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  349. --
  350. ALTER TABLE ONLY public.knowledge_points
  351. ADD CONSTRAINT knowledge_points_pkey PRIMARY KEY (id);
  352. --
  353. -- Name: messages messages_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  354. --
  355. ALTER TABLE ONLY public.messages
  356. ADD CONSTRAINT messages_pkey PRIMARY KEY (id);
  357. --
  358. -- Name: questions questions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  359. --
  360. ALTER TABLE ONLY public.questions
  361. ADD CONSTRAINT questions_pkey PRIMARY KEY (id);
  362. --
  363. -- Name: user_progress user_progress_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  364. --
  365. ALTER TABLE ONLY public.user_progress
  366. ADD CONSTRAINT user_progress_pkey PRIMARY KEY (id);
  367. --
  368. -- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
  369. --
  370. ALTER TABLE ONLY public.users
  371. ADD CONSTRAINT users_pkey PRIMARY KEY (id);
  372. --
  373. -- Name: idx_drug_chunks_vec; Type: INDEX; Schema: public; Owner: -
  374. --
  375. CREATE INDEX idx_drug_chunks_vec ON public.drug_chunks USING ivfflat (vec) WITH (lists='10');
  376. --
  377. -- Name: ix_answer_records_question_id; Type: INDEX; Schema: public; Owner: -
  378. --
  379. CREATE INDEX ix_answer_records_question_id ON public.answer_records USING btree (question_id);
  380. --
  381. -- Name: ix_answer_records_user_id; Type: INDEX; Schema: public; Owner: -
  382. --
  383. CREATE INDEX ix_answer_records_user_id ON public.answer_records USING btree (user_id);
  384. --
  385. -- Name: ix_conversations_conversation_id; Type: INDEX; Schema: public; Owner: -
  386. --
  387. CREATE UNIQUE INDEX ix_conversations_conversation_id ON public.conversations USING btree (conversation_id);
  388. --
  389. -- Name: ix_drug_chunks_drug_id; Type: INDEX; Schema: public; Owner: -
  390. --
  391. CREATE INDEX ix_drug_chunks_drug_id ON public.drug_chunks USING btree (drug_id);
  392. --
  393. -- Name: ix_drugs_category; Type: INDEX; Schema: public; Owner: -
  394. --
  395. CREATE INDEX ix_drugs_category ON public.drugs USING btree (category);
  396. --
  397. -- Name: ix_drugs_drug_id; Type: INDEX; Schema: public; Owner: -
  398. --
  399. CREATE UNIQUE INDEX ix_drugs_drug_id ON public.drugs USING btree (drug_id);
  400. --
  401. -- Name: ix_drugs_name; Type: INDEX; Schema: public; Owner: -
  402. --
  403. CREATE INDEX ix_drugs_name ON public.drugs USING btree (name);
  404. --
  405. -- Name: ix_knowledge_points_chapter_id; Type: INDEX; Schema: public; Owner: -
  406. --
  407. CREATE INDEX ix_knowledge_points_chapter_id ON public.knowledge_points USING btree (chapter_id);
  408. --
  409. -- Name: ix_knowledge_points_point_id; Type: INDEX; Schema: public; Owner: -
  410. --
  411. CREATE UNIQUE INDEX ix_knowledge_points_point_id ON public.knowledge_points USING btree (point_id);
  412. --
  413. -- Name: ix_knowledge_points_subject; Type: INDEX; Schema: public; Owner: -
  414. --
  415. CREATE INDEX ix_knowledge_points_subject ON public.knowledge_points USING btree (subject);
  416. --
  417. -- Name: ix_knowledge_points_vector_id; Type: INDEX; Schema: public; Owner: -
  418. --
  419. CREATE INDEX ix_knowledge_points_vector_id ON public.knowledge_points USING btree (vector_id);
  420. --
  421. -- Name: ix_messages_conversation_id; Type: INDEX; Schema: public; Owner: -
  422. --
  423. CREATE INDEX ix_messages_conversation_id ON public.messages USING btree (conversation_id);
  424. --
  425. -- Name: ix_questions_chapter_id; Type: INDEX; Schema: public; Owner: -
  426. --
  427. CREATE INDEX ix_questions_chapter_id ON public.questions USING btree (chapter_id);
  428. --
  429. -- Name: ix_questions_question_id; Type: INDEX; Schema: public; Owner: -
  430. --
  431. CREATE UNIQUE INDEX ix_questions_question_id ON public.questions USING btree (question_id);
  432. --
  433. -- Name: ix_questions_subject; Type: INDEX; Schema: public; Owner: -
  434. --
  435. CREATE INDEX ix_questions_subject ON public.questions USING btree (subject);
  436. --
  437. -- Name: ix_user_progress_chapter_id; Type: INDEX; Schema: public; Owner: -
  438. --
  439. CREATE INDEX ix_user_progress_chapter_id ON public.user_progress USING btree (chapter_id);
  440. --
  441. -- Name: ix_user_progress_knowledge_point_id; Type: INDEX; Schema: public; Owner: -
  442. --
  443. CREATE INDEX ix_user_progress_knowledge_point_id ON public.user_progress USING btree (knowledge_point_id);
  444. --
  445. -- Name: ix_user_progress_subject; Type: INDEX; Schema: public; Owner: -
  446. --
  447. CREATE INDEX ix_user_progress_subject ON public.user_progress USING btree (subject);
  448. --
  449. -- Name: ix_user_progress_user_id; Type: INDEX; Schema: public; Owner: -
  450. --
  451. CREATE INDEX ix_user_progress_user_id ON public.user_progress USING btree (user_id);
  452. --
  453. -- Name: ix_users_openid; Type: INDEX; Schema: public; Owner: -
  454. --
  455. CREATE UNIQUE INDEX ix_users_openid ON public.users USING btree (openid);
  456. --
  457. -- Name: ix_drugs_sections_gin; Type: INDEX; Schema: public; Owner: -
  458. --
  459. CREATE INDEX ix_drugs_sections_gin ON public.drugs USING gin (sections);
  460. --
  461. -- Name: ix_drugs_source_version; Type: INDEX; Schema: public; Owner: -
  462. --
  463. CREATE INDEX ix_drugs_source_version ON public.drugs USING btree (source_version);
  464. --
  465. -- Name: answer_records answer_records_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
  466. --
  467. ALTER TABLE ONLY public.answer_records
  468. ADD CONSTRAINT answer_records_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
  469. --
  470. -- Name: messages messages_conversation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
  471. --
  472. ALTER TABLE ONLY public.messages
  473. ADD CONSTRAINT messages_conversation_id_fkey FOREIGN KEY (conversation_id) REFERENCES public.conversations(conversation_id);
  474. --
  475. -- Name: user_progress user_progress_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
  476. --
  477. ALTER TABLE ONLY public.user_progress
  478. ADD CONSTRAINT user_progress_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
  479. --
  480. -- PostgreSQL database dump complete
  481. --
  482. \unrestrict ESQ1NFAz6xVH1qNjdPPTbrmPbtepjMOr7SzmqGUWW2SDRd1pbhCctBfDStfCiB2