-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.sql
132 lines (98 loc) · 3.21 KB
/
init.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
CREATE TYPE public.remindertype AS ENUM
('QUIZ', 'ASSIGN', 'PAGE');
-- Type: typerolechoices
-- DROP TYPE IF EXISTS public.typerolechoices;
CREATE TYPE public.typerolechoices AS ENUM
('BOT', 'USER');
CREATE SEQUENCE IF NOT EXISTS public.messages_chatbot_deleted_id_seq
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 2147483647
CACHE 1;
CREATE SEQUENCE IF NOT EXISTS public.messages_chatbot_id_seq
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 2147483647
CACHE 1;
CREATE SEQUENCE IF NOT EXISTS public.messages_reminders_chatbot_id_seq
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 2147483647
CACHE 1;
CREATE TABLE IF NOT EXISTS public.messages_chatbot
(
created_at timestamp without time zone,
content character varying COLLATE pg_catalog."default" NOT NULL,
"chatId" integer NOT NULL,
role typerolechoices NOT NULL,
id integer NOT NULL DEFAULT nextval('messages_chatbot_id_seq'::regclass),
CONSTRAINT messages_chatbot_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
-- Table: public.messages_chatbot_deleted
-- DROP TABLE IF EXISTS public.messages_chatbot_deleted;
CREATE TABLE IF NOT EXISTS public.messages_chatbot_deleted
(
created_at timestamp without time zone,
content character varying COLLATE pg_catalog."default" NOT NULL,
"chatId" integer NOT NULL,
role typerolechoices NOT NULL,
id integer NOT NULL DEFAULT nextval('messages_chatbot_deleted_id_seq'::regclass),
CONSTRAINT messages_chatbot_deleted_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
-- Table: public.messages_reminders_chatbot
-- DROP TABLE IF EXISTS public.messages_reminders_chatbot;
CREATE TABLE IF NOT EXISTS public.messages_reminders_chatbot
(
created_at timestamp without time zone,
id integer NOT NULL DEFAULT nextval('messages_reminders_chatbot_id_seq'::regclass),
type character varying COLLATE pg_catalog."default" NOT NULL,
content character varying COLLATE pg_catalog."default" NOT NULL,
"chatId" integer NOT NULL,
time_remind timestamp without time zone NOT NULL,
is_remind boolean NOT NULL,
CONSTRAINT messages_reminders_chatbot_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
--- create table embedding
CREATE EXTENSION IF NOT EXISTS vector
CREATE TABLE embeddings_v2 (
id bigserial primary key,
courseId interger,
title text,
url text,
content text,
tokens integer,
embedding vector(768)
)
ALTER TABLE embeddings_v2
ADD CONSTRAINT unique_url UNIQUE (url);
---
create or replace function get_course_of_user(user_id int)
returns table (course_id int8, course_name text)
as
$body$
SELECT c.id AS course_id, c.fullname
FROM mdl_user u
JOIN mdl_user_enrolments ue ON u.id = ue.userid
JOIN mdl_enrol e ON ue.enrolid = e.id
JOIN mdl_course c ON e.courseid = c.id
WHERE u.id = $1
ORDER BY ue.timestart DESC
LIMIT 5;
$body$
language sql;
select get_course_of_user(3)