-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgresql_queries.sql
107 lines (89 loc) · 2.61 KB
/
postgresql_queries.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
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
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
CREATE TABLE users (
id VARCHAR PRIMARY KEY,
username VARCHAR UNIQUE NOT NULL,
password VARCHAR NOT NULL,
email VARCHAR UNIQUE NOT NULL,
first_name VARCHAR(50),
last_name VARCHAR(50),
last_login TIMESTAMP DEFAULT NOW(),
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE ideas (
id VARCHAR PRIMARY KEY,
category VARCHAR NOT NULL,
name VARCHAR NOT NULL,
description VARCHAR,
target VARCHAR,
favorite BOOLEAN DEFAULT FALSE,
archive BOOLEAN DEFAULT FALSE,
last_edited TIMESTAMP DEFAULT NOW(),
created_at TIMESTAMP DEFAULT NOW(),
user_id VARCHAR NOT NULL,
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE TABLE features (
id VARCHAR PRIMARY KEY,
text VARCHAR,
favorite BOOLEAN DEFAULT FALSE,
archive BOOLEAN DEFAULT FALSE,
last_edited TIMESTAMP DEFAULT NOW(),
created_at TIMESTAMP DEFAULT NOW(),
idea_id VARCHAR NOT NULL,
user_id VARCHAR NOT NULL,
FOREIGN KEY(idea_id) REFERENCES ideas(id),
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE TABLE strategies (
id VARCHAR PRIMARY KEY,
text VARCHAR,
favorite BOOLEAN DEFAULT FALSE,
archive BOOLEAN DEFAULT FALSE,
last_edited TIMESTAMP DEFAULT NOW(),
created_at TIMESTAMP DEFAULT NOW(),
idea_id VARCHAR NOT NULL,
user_id VARCHAR NOT NULL,
FOREIGN KEY(idea_id) REFERENCES ideas(id),
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE TABLE inspiration (
id VARCHAR PRIMARY KEY,
text VARCHAR,
favorite BOOLEAN DEFAULT FALSE,
archive BOOLEAN DEFAULT FALSE,
last_edited TIMESTAMP DEFAULT NOW(),
created_at TIMESTAMP DEFAULT NOW(),
idea_id VARCHAR NOT NULL,
user_id VARCHAR NOT NULL,
FOREIGN KEY(idea_id) REFERENCES ideas(id),
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE TABLE resources (
id VARCHAR PRIMARY KEY,
text VARCHAR,
favorite BOOLEAN DEFAULT FALSE,
archive BOOLEAN DEFAULT FALSE,
last_edited TIMESTAMP DEFAULT NOW(),
created_at TIMESTAMP DEFAULT NOW(),
idea_id VARCHAR NOT NULL,
user_id VARCHAR NOT NULL,
FOREIGN KEY(idea_id) REFERENCES ideas(id),
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE TABLE tags (
id VARCHAR PRIMARY KEY,
tag_name VARCHAR UNIQUE,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE idea_tags (
idea_id VARCHAR NOT NULL,
tag_id VARCHAR NOT NULL,
FOREIGN KEY(idea_id) REFERENCES ideas(id),
FOREIGN KEY(tag_id) REFERENCES tags(id),
PRIMARY KEY(idea_id, tag_id)
);
INSERT INTO users(id, username, password, email) VALUES
('user1', '[email protected]', 'user1', '[email protected]');
INSERT INTO ideas(id, category, name, user_id) VALUES
('idea1', 'books', 'Book Idea', 'user1');