-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.sql
58 lines (51 loc) · 1.57 KB
/
data.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
CREATE TABLE sites (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
url TEXT NOT NULL,
count INTEGER DEFAULT 1
);
CREATE TABLE messages (
id SERIAL PRIMARY KEY,
username VARCHAR(50) NOT NULL,
text TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 기존 테이블 삭제
DROP TABLE IF EXISTS users CASCADE;
-- 새로운 users 테이블 생성
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(100) NOT NULL,
is_teacher BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 세션 테이블 추가
CREATE TABLE "session" (
"sid" varchar NOT NULL COLLATE "default",
"sess" json NOT NULL,
"expire" timestamp(6) NOT NULL
);
ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
CREATE INDEX "IDX_session_expire" ON "session" ("expire");
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
type VARCHAR(10) NOT NULL,
title VARCHAR(200) NOT NULL,
content TEXT NOT NULL,
author VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_teacher BOOLEAN DEFAULT FALSE
);
-- comments 테이블 수정
DROP TABLE IF EXISTS comments CASCADE;
CREATE TABLE comments (
id SERIAL PRIMARY KEY,
post_id INTEGER REFERENCES posts(id),
content TEXT NOT NULL,
author VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_accepted BOOLEAN DEFAULT FALSE,
accepted_by VARCHAR(100),
accepted_by_teacher BOOLEAN DEFAULT FALSE
);