-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathtwitter-schema.sql
40 lines (35 loc) · 922 Bytes
/
twitter-schema.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
-- sqlite3 database.db < twitter-schema.sql
PRAGMA foreign_keys = ON;
DROP TABLE if exists user;
CREATE TABLE user (
id INTEGER PRIMARY KEY autoincrement,
username TEXT NOT NULL,
password TEXT NOT NULL,
first_name TEXT,
last_name TEXT,
birth_date DATE,
CHECK (
length("birth_date") = 10
)
);
DROP TABLE if exists tweet;
CREATE TABLE tweet (
id INTEGER PRIMARY KEY autoincrement,
user_id INTEGER,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
content TEXT NOT NULL,
FOREIGN KEY(user_id) REFERENCES user(id),
CHECK(
typeof("content") = "text" AND
length("content") <= 140
)
);
DROP TABLE if exists auth;
CREATE TABLE auth (
id INTEGER PRIMARY KEY autoincrement,
user_id INTEGER,
access_token TEXT NOT NULL,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(user_id) REFERENCES user(id)
);
CREATE UNIQUE INDEX auth_access_token_idx ON auth (access_token);