File size: 11,831 Bytes
689b093 | 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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | --
-- Name: account; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.account (
id integer NOT NULL,
display_name character varying,
location character varying,
about_me character varying,
website_url character varying
);
--
-- Name: answer; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.answer (
id integer NOT NULL,
site_id integer NOT NULL,
question_id integer,
creation_date timestamp without time zone,
deletion_date timestamp without time zone,
score integer,
view_count integer,
body character varying,
owner_user_id integer,
last_editor_id integer,
last_edit_date timestamp without time zone,
last_activity_date timestamp without time zone,
title character varying
);
--
-- Name: badge; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.badge (
site_id integer NOT NULL,
user_id integer NOT NULL,
name character varying NOT NULL,
date timestamp without time zone NOT NULL
);
--
-- Name: comment; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.comment (
id integer NOT NULL,
site_id integer NOT NULL,
post_id integer,
user_id integer,
score integer,
body character varying,
date timestamp without time zone
);
--
-- Name: post_link; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.post_link (
site_id integer NOT NULL,
post_id_from integer NOT NULL,
post_id_to integer NOT NULL,
link_type integer NOT NULL,
date timestamp without time zone
);
--
-- Name: question; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.question (
id integer NOT NULL,
site_id integer NOT NULL,
accepted_answer_id integer,
creation_date timestamp without time zone,
deletion_date timestamp without time zone,
score integer,
view_count integer,
body character varying,
owner_user_id integer,
last_editor_id integer,
last_edit_date timestamp without time zone,
last_activity_date timestamp without time zone,
title character varying,
favorite_count integer,
closed_date timestamp without time zone,
tagstring character varying
);
--
-- Name: site; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.site (
site_id integer NOT NULL,
site_name character varying
);
--
-- Name: so_user; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.so_user (
id integer NOT NULL,
site_id integer NOT NULL,
reputation integer,
creation_date timestamp without time zone,
last_access_date timestamp without time zone,
upvotes integer,
downvotes integer,
account_id integer
);
--
-- Name: tag; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.tag (
id integer NOT NULL,
site_id integer NOT NULL,
name character varying
);
--
-- Name: tag_question; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.tag_question (
question_id integer NOT NULL,
tag_id integer NOT NULL,
site_id integer NOT NULL
);
--
-- Name: account account_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.account
ADD CONSTRAINT account_pkey PRIMARY KEY (id);
--
-- Name: answer answer_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.answer
ADD CONSTRAINT answer_pkey PRIMARY KEY (id, site_id);
--
-- Name: badge badge_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.badge
ADD CONSTRAINT badge_pkey PRIMARY KEY (site_id, user_id, name, date);
--
-- Name: comment comment_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.comment
ADD CONSTRAINT comment_pkey PRIMARY KEY (id, site_id);
--
-- Name: post_link post_link_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.post_link
ADD CONSTRAINT post_link_pkey PRIMARY KEY (site_id, post_id_from, post_id_to, link_type);
--
-- Name: question question_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.question
ADD CONSTRAINT question_pkey PRIMARY KEY (id, site_id);
--
-- Name: site site_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.site
ADD CONSTRAINT site_pkey PRIMARY KEY (site_id);
--
-- Name: so_user so_user_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.so_user
ADD CONSTRAINT so_user_pkey PRIMARY KEY (id, site_id);
--
-- Name: tag tag_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.tag
ADD CONSTRAINT tag_pkey PRIMARY KEY (id, site_id);
--
-- Name: tag_question tag_question_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.tag_question
ADD CONSTRAINT tag_question_pkey PRIMARY KEY (site_id, question_id, tag_id);
--
-- Name: answer_creation_date_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX answer_creation_date_idx ON public.answer USING btree (creation_date);
--
-- Name: answer_last_editor_id_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX answer_last_editor_id_idx ON public.answer USING btree (last_editor_id);
--
-- Name: answer_owner_user_id_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX answer_owner_user_id_idx ON public.answer USING btree (owner_user_id);
--
-- Name: answer_site_id_question_id_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX answer_site_id_question_id_idx ON public.answer USING btree (site_id, question_id);
--
-- Name: comment_site_id_post_id_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX comment_site_id_post_id_idx ON public.comment USING btree (site_id, post_id);
--
-- Name: comment_site_id_user_id_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX comment_site_id_user_id_idx ON public.comment USING btree (site_id, user_id);
--
-- Name: question_creation_date_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX question_creation_date_idx ON public.question USING btree (creation_date);
--
-- Name: question_last_editor_id_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX question_last_editor_id_idx ON public.question USING btree (last_editor_id);
--
-- Name: question_owner_user_id_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX question_owner_user_id_idx ON public.question USING btree (owner_user_id);
--
-- Name: so_user_creation_date_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX so_user_creation_date_idx ON public.so_user USING btree (creation_date);
--
-- Name: so_user_last_access_date_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX so_user_last_access_date_idx ON public.so_user USING btree (last_access_date);
--
-- Name: tag_question_site_id_tag_id_question_id_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX tag_question_site_id_tag_id_question_id_idx ON public.tag_question USING btree (site_id, tag_id, question_id);
--
-- Name: answer answer_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.answer
ADD CONSTRAINT answer_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.site(site_id);
--
-- Name: answer answer_site_id_fkey1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.answer
ADD CONSTRAINT answer_site_id_fkey1 FOREIGN KEY (site_id, owner_user_id) REFERENCES public.so_user(site_id, id);
--
-- Name: answer answer_site_id_fkey2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.answer
ADD CONSTRAINT answer_site_id_fkey2 FOREIGN KEY (site_id, last_editor_id) REFERENCES public.so_user(site_id, id);
--
-- Name: answer answer_site_id_fkey3; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.answer
ADD CONSTRAINT answer_site_id_fkey3 FOREIGN KEY (site_id, question_id) REFERENCES public.question(site_id, id);
--
-- Name: badge badge_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.badge
ADD CONSTRAINT badge_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.site(site_id);
--
-- Name: badge badge_site_id_fkey1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.badge
ADD CONSTRAINT badge_site_id_fkey1 FOREIGN KEY (site_id, user_id) REFERENCES public.so_user(site_id, id);
--
-- Name: comment comment_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.comment
ADD CONSTRAINT comment_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.site(site_id);
--
-- Name: post_link post_link_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.post_link
ADD CONSTRAINT post_link_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.site(site_id);
--
-- Name: post_link post_link_site_id_fkey1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.post_link
ADD CONSTRAINT post_link_site_id_fkey1 FOREIGN KEY (site_id, post_id_to) REFERENCES public.question(site_id, id);
--
-- Name: post_link post_link_site_id_fkey2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.post_link
ADD CONSTRAINT post_link_site_id_fkey2 FOREIGN KEY (site_id, post_id_from) REFERENCES public.question(site_id, id);
--
-- Name: question question_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.question
ADD CONSTRAINT question_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.site(site_id);
--
-- Name: question question_site_id_fkey1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.question
ADD CONSTRAINT question_site_id_fkey1 FOREIGN KEY (site_id, owner_user_id) REFERENCES public.so_user(site_id, id);
--
-- Name: question question_site_id_fkey2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.question
ADD CONSTRAINT question_site_id_fkey2 FOREIGN KEY (site_id, last_editor_id) REFERENCES public.so_user(site_id, id);
--
-- Name: so_user so_user_account_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.so_user
ADD CONSTRAINT so_user_account_id_fkey FOREIGN KEY (account_id) REFERENCES public.account(id);
--
-- Name: so_user so_user_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.so_user
ADD CONSTRAINT so_user_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.site(site_id);
--
-- Name: tag_question tag_question_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.tag_question
ADD CONSTRAINT tag_question_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.site(site_id);
--
-- Name: tag_question tag_question_site_id_fkey1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.tag_question
ADD CONSTRAINT tag_question_site_id_fkey1 FOREIGN KEY (site_id, tag_id) REFERENCES public.tag(site_id, id);
--
-- Name: tag_question tag_question_site_id_fkey2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.tag_question
ADD CONSTRAINT tag_question_site_id_fkey2 FOREIGN KEY (site_id, question_id) REFERENCES public.question(site_id, id) ON DELETE CASCADE;
--
-- Name: tag tag_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.tag
ADD CONSTRAINT tag_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.site(site_id);
|