-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_schema.sql
More file actions
56 lines (48 loc) · 1.54 KB
/
db_schema.sql
File metadata and controls
56 lines (48 loc) · 1.54 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
-- Enable foreign key constraints
PRAGMA foreign_keys=ON;
-- Begin a transaction
BEGIN TRANSACTION;
-- For storing author & blog title
CREATE TABLE IF NOT EXISTS names (
names_id INTEGER PRIMARY KEY AUTOINCREMENT,
author_name TEXT NOT NULL,
author_about TEXT NOT NULL
);
-- For storing drafted blogs/blogs
CREATE TABLE IF NOT EXISTS blog (
blog_id INTEGER PRIMARY KEY AUTOINCREMENT,
blog_title TEXT NOT NULL,
blog_content TEXT NOT NULL,
created_at DEFAULT CURRENT_TIMESTAMP,
published_at TIMESTAMP,
modified_at TIMESTAMP,
blog_status TEXT NOT NULL
);
-- For storing published blogs/blogs
CREATE TABLE IF NOT EXISTS publishBlog (
publish_id INTEGER PRIMARY KEY AUTOINCREMENT,
blog_id INTEGER,
blog_title TEXT NOT NULL,
blog_content TEXT NOT NULL,
created_at TIMESTAMP,
published_at DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP,
blog_status TEXT NOT NULL,
blog_reads INTEGER DEFAULT 0,
blog_likes INTEGER DEFAULT 0,
FOREIGN KEY (blog_id) REFERENCES blog(blog_id)
);
-- For storing comments
CREATE TABLE IF NOT EXISTS comments (
comment_id INTEGER PRIMARY KEY AUTOINCREMENT,
publish_id INTEGER,
commentator_name TEXT NOT NULL,
comment TEXT NOT NULL,
comment_likes INTEGER DEFAULT 0,
commented_at DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (publish_id) REFERENCES publishBlog(publish_id)
);
-- Initial Dumy data for author name & blog title
INSERT INTO names (author_name, author_about) VALUES ('Author Name', 'Author About');
-- Commit the transaction
COMMIT;