-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
179 lines (159 loc) · 5.31 KB
/
Copy pathschema.sql
File metadata and controls
179 lines (159 loc) · 5.31 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
-- 1. Create Independent/Parent Tables
CREATE TABLE Institution (
institution_id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
subscription_status VARCHAR(50),
PRIMARY KEY (institution_id)
);
CREATE TABLE Domain (
domain_id INT(11) NOT NULL AUTO_INCREMENT,
domain_topic VARCHAR(255),
semantic_embedding VECTOR(1024),
PRIMARY KEY (domain_id)
);
CREATE TABLE Venue (
venue_id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(255),
type VARCHAR(50),
url VARCHAR(255),
PRIMARY KEY (venue_id)
);
-- 2. Create Tables with Single Dependencies
CREATE TABLE User (
user_id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
role VARCHAR(50),
institution_id INT(11),
semantic_embedding VECTOR(1024),
PRIMARY KEY (user_id),
FOREIGN KEY (institution_id) REFERENCES Institution(institution_id)
);
CREATE TABLE Search_Queries (
query_id INT(11) NOT NULL AUTO_INCREMENT,
query_text VARCHAR(500) NOT NULL,
optimized_text TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
user_id INT(11),
type VARCHAR(50),
semantic_embedding VECTOR(1024),
expires_at DATETIME NOT NULL DEFAULT (CURRENT_TIMESTAMP + INTERVAL 1 YEAR),
PRIMARY KEY (query_id),
FOREIGN KEY (user_id) REFERENCES User(user_id)
);
CREATE TABLE Job_Posting (
job_id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
description TEXT,
budget DECIMAL(10,2),
posted_by VARCHAR(255),
poster_user_id INT(11),
domain_id INT(11),
status VARCHAR(50),
type VARCHAR(50),
semantic_embedding VECTOR(1024),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (job_id),
FOREIGN KEY (domain_id) REFERENCES Domain(domain_id),
FOREIGN KEY (poster_user_id) REFERENCES User(user_id)
);
CREATE TABLE Job_Application (
application_id INT(11) NOT NULL AUTO_INCREMENT,
job_id INT(11) NOT NULL,
applicant_id INT(11) NOT NULL,
cover_letter TEXT,
proposed_budget DECIMAL(10,2),
status VARCHAR(50) DEFAULT 'pending',
applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (application_id),
FOREIGN KEY (job_id) REFERENCES Job_Posting(job_id),
FOREIGN KEY (applicant_id) REFERENCES User(user_id)
);
CREATE TABLE Research_Paper (
paper_id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
abstract TEXT,
year INT(11),
citation_count INT(11) DEFAULT 0,
quality_score DECIMAL(3,2),
publication_type VARCHAR(50),
venue_id INT(11),
domain_id INT(11),
semantic_embedding VECTOR(1024),
url VARCHAR(255),
PRIMARY KEY (paper_id),
FOREIGN KEY (venue_id) REFERENCES Venue(venue_id),
FOREIGN KEY (domain_id) REFERENCES Domain(domain_id)
);
-- 3. Create Relationship/Link Tables
CREATE TABLE Authorship (
user_id INT(11) NOT NULL,
paper_id INT(11) NOT NULL,
contribution_order INT(11),
PRIMARY KEY (user_id, paper_id),
FOREIGN KEY (user_id) REFERENCES User(user_id),
FOREIGN KEY (paper_id) REFERENCES Research_Paper(paper_id)
);
CREATE TABLE Has_Interest_In (
user_id INT(11) NOT NULL,
domain_id INT(11) NOT NULL,
PRIMARY KEY (user_id, domain_id),
FOREIGN KEY (user_id) REFERENCES User(user_id),
FOREIGN KEY (domain_id) REFERENCES Domain(domain_id)
);
CREATE TABLE IS_AFFLIATED_WITH (
user_id INT(11) NOT NULL,
institution_id INT(11) NOT NULL,
PRIMARY KEY (user_id, institution_id),
FOREIGN KEY (user_id) REFERENCES User(user_id),
FOREIGN KEY (institution_id) REFERENCES Institution(institution_id)
);
CREATE TABLE Job_Belongs_To (
job_id INT(11) NOT NULL,
domain_id INT(11) NOT NULL,
PRIMARY KEY (job_id, domain_id),
FOREIGN KEY (job_id) REFERENCES Job_Posting(job_id),
FOREIGN KEY (domain_id) REFERENCES Domain(domain_id)
);
CREATE TABLE Jobs_Returned (
job_id INT(11) NOT NULL,
query_id INT(11) NOT NULL,
PRIMARY KEY (job_id, query_id),
FOREIGN KEY (job_id) REFERENCES Job_Posting(job_id),
FOREIGN KEY (query_id) REFERENCES Search_Queries(query_id)
);
CREATE TABLE Paper_Belongs_To (
paper_id INT(11) NOT NULL,
domain_id INT(11) NOT NULL,
PRIMARY KEY (paper_id, domain_id),
FOREIGN KEY (paper_id) REFERENCES Research_Paper(paper_id),
FOREIGN KEY (domain_id) REFERENCES Domain(domain_id)
);
CREATE TABLE Published_In (
venue_id INT(11) NOT NULL,
paper_id INT(11) NOT NULL,
PRIMARY KEY (venue_id, paper_id),
FOREIGN KEY (venue_id) REFERENCES Venue(venue_id),
FOREIGN KEY (paper_id) REFERENCES Research_Paper(paper_id)
);
CREATE TABLE Research_Paper_Returned (
paper_id INT(11) NOT NULL,
query_id INT(11) NOT NULL,
PRIMARY KEY (paper_id, query_id),
FOREIGN KEY (paper_id) REFERENCES Research_Paper(paper_id),
FOREIGN KEY (query_id) REFERENCES Search_Queries(query_id)
);
CREATE TABLE Searches (
user_id INT(11) NOT NULL,
query_id INT(11) NOT NULL,
PRIMARY KEY (user_id, query_id),
FOREIGN KEY (user_id) REFERENCES User(user_id),
FOREIGN KEY (query_id) REFERENCES Search_Queries(query_id)
);
CREATE TABLE Subscribes_To (
venue_id INT(11) NOT NULL,
institution_id INT(11) NOT NULL,
PRIMARY KEY (venue_id, institution_id),
FOREIGN KEY (venue_id) REFERENCES Venue(venue_id),
FOREIGN KEY (institution_id) REFERENCES Institution(institution_id)
);