forked from HR-FitBud/fitbud
-
Notifications
You must be signed in to change notification settings - Fork 4
/
schema.sql
101 lines (79 loc) · 2.79 KB
/
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
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
DROP DATABASE IF EXISTS fitbud;
CREATE DATABASE fitbud;
USE fitbud;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS postings;
DROP TABLE IF EXISTS profile;
DROP TABLE IF EXISTS requests;
CREATE TABLE users (
id int NOT NULL AUTO_INCREMENT,
fb_id varchar(50) UNIQUE,
photo varchar(100),
name varchar(255) NOT NULL,
email varchar(255) NOT NULL,
password varchar(255),
description varchar(255) DEFAULT '',
friendsNum INT(5) DEFAULT 0,
PRIMARY KEY (id)
);
INSERT INTO users (name, email, password, photo, friendsNum) VALUES ('Victor Wang', '[email protected]', 'qwertyui', '/daniel.jpg',0);
INSERT INTO users (name, email, password, photo, friendsNum) VALUES ('kevin', '[email protected]', 'hahaha', '/elliot.jpg',0);
INSERT INTO users (name, email, password, photo, friendsNum) VALUES ('albert', '[email protected]', 'hahaha', '/matthew.png',0);
INSERT INTO users (name, email, password, photo, friendsNum) VALUES ('umi', '[email protected]', 'hahaha', '/rachel.png',0);
CREATE TABLE friends (
id INT NOT NULL AUTO_INCREMENT,
originator INT NOT NULL,
receiver INT NOT NULL,
status ENUM('pending', 'accept', 'reject'),
PRIMARY KEY (id),
FOREIGN KEY (originator) REFERENCES users(id),
FOREIGN KEY (receiver) REFERENCES users(id)
);
INSERT INTO friends (originator, receiver, status) VALUES (1, 2, 'pending');
UPDATE friends SET STATUS='accept' WHERE (originator=1 AND receiver=2);
INSERT INTO friends (originator, receiver, status) VALUES (3, 1, 'accept');
INSERT INTO friends (originator, receiver, status) VALUES (4, 1, 'accept');
CREATE TABLE postings (
id INT NOT NULL AUTO_INCREMENT,
title varchar(50),
location varchar(255) NOT NULL,
date DATETIME,
duration INT NOT NULL,
details varchar(255) NOT NULL,
meetup_spot varchar(255) NOT NULL,
buddies INT NOT NULL,
userId INT,
private boolean,
currentEvent INT,
currentLevel ENUM('Beginner','Intermediate','Advanced'),
photo varchar(100),
PRIMARY KEY (id),
FOREIGN KEY (userId) REFERENCES users(id)
);
CREATE TABLE profile (
id INT NOT NULL AUTO_INCREMENT,
gender varchar(20),
activity varchar(255) NOT NULL,
userId INT,
PRIMARY KEY (id),
FOREIGN KEY (userId) REFERENCES users(id)
);
CREATE TABLE requests (
id INT NOT NULL AUTO_INCREMENT,
postingId INT,
userId INT,
status ENUM('pending', 'accept', 'reject'),
PRIMARY KEY (id),
FOREIGN KEY (postingId) REFERENCES postings(id),
FOREIGN KEY (userId) REFERENCES users(id)
);
DROP TABLE IF EXISTS subscription;
CREATE TABLE subscription (
id INT NOT NULL AUTO_INCREMENT,
subscriberId INT NOT NULL,
publisherId INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (subscriberId) REFERENCES users(id),
FOREIGN KEY (publisherId) REFERENCES users(id)
);
select postings.*, users.name from postings inner join users on postings.userId=users.id where postings.id=3;