-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdegrees_db.sql
177 lines (152 loc) · 5.12 KB
/
degrees_db.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
DROP DATABASE IF EXISTS degrees_db;
CREATE DATABASE degrees_db;
USE degrees_db;
DROP TABLE IF EXISTS Users;
DROP TABLE IF EXISTS Non_profits;
DROP TABLE IF EXISTS Challenges;
DROP TABLE IF EXISTS Actions;
DROP TABLE IF EXISTS ChallengeActions;
DROP TABLE IF EXISTS UserInvites;
DROP TABLE IF EXISTS UserParticipations;
CREATE TABLE IF NOT EXISTS Users(
user_id INT AUTO_INCREMENT,
first_name TEXT,
last_name TEXT,
user_email TEXT,
user_pass TEXT,
PRIMARY KEY (user_id)
);
show tables;
select * from Users;
CREATE TABLE IF NOT EXISTS Non_profits(
np_id INT AUTO_INCREMENT,
np_name TEXT,
np_email TEXT,
np_pass TEXT,
summary TEXT,
PRIMARY KEY (np_id)
);
CREATE TABLE IF NOT EXISTS Challenges(
c_id INT AUTO_INCREMENT,
c_name VARCHAR(255),
user_id INT,
np_id INT,
PRIMARY KEY (c_id),
UNIQUE (c_name)
);
ALTER TABLE Challenges
ADD FOREIGN KEY (user_id) REFERENCES Users (user_id);
CREATE TABLE IF NOT EXISTS Actions(
a_id INT AUTO_INCREMENT,
a_name TEXT,
val INT,
PRIMARY KEY (a_id)
);
CREATE TABLE IF NOT EXISTS ChallengeActions(
c_id INT,
a_id INT,
PRIMARY KEY (c_id, a_id)
);
ALTER TABLE ChallengeActions
ADD FOREIGN KEY (c_id) REFERENCES Challenges (c_id);
ALTER TABLE ChallengeActions
ADD FOREIGN KEY (a_id) REFERENCES Actions (a_id);
CREATE TABLE IF NOT EXISTS UserInvites(
user_id1 INT,
user_id2 INT,
c_id INT,
PRIMARY KEY (user_id1, user_id2, c_id)
);
ALTER TABLE UserInvites
ADD FOREIGN KEY (user_id1) REFERENCES Users (user_id);
ALTER TABLE UserInvites
ADD FOREIGN KEY (user_id2) REFERENCES Users (user_id);
ALTER TABLE UserInvites
ADD FOREIGN KEY (c_id) REFERENCES Challenges (c_id);
CREATE TABLE IF NOT EXISTS UserParticipations(
user_id INT,
c_id INT,
a_id INT,
ContrVal INT,
PRIMARY KEY (user_id, c_id, a_id)
);
ALTER TABLE UserParticipations
ADD FOREIGN KEY (user_id) REFERENCES Users (user_id);
ALTER TABLE UserParticipations
ADD FOREIGN KEY (c_id) REFERENCES Challenges (c_id);
INSERT INTO Users (first_name, last_name, user_email, user_pass)
VALUES('Kai', 'Wong', '[email protected]', 'kaiWong1'),
('Wendy', 'Ni', '[email protected]', 'wendyNi1'),
('Dayna', 'Eidle', '[email protected]', 'daynaEidle1'),
('Kai3', 'Wong3', '[email protected]', 'kaiWong3'),
('Wendy2', 'Ni2', '[email protected]', 'wendyNi2'),
('Dayna2', 'Eidle2', '[email protected]', 'daynaEidle2'),
('Kai2', 'Wong2', '[email protected]', 'kaiWong2'),
('Jess', 'Ni', '[email protected]', 'JessNi1'),
('Kai', 'Eidle', '[email protected]', 'KaiEidle1'),
('Wendy', 'Wong', '[email protected]', 'WendyWong1'),
('Jamie', 'Nie', '[email protected]', 'JamieNie1'),
('Katy', 'Eidle', '[email protected]', 'KatyEidle1'),
('Tyler', 'Wong', '[email protected]', 'TylerWong1'),
('Jess', 'Rieger', '[email protected]', 'JessRieger1'),
('Wendy', 'Whel', '[email protected]', 'WendyWhel1'),
('Wendy', 'Whelan', '[email protected]', 'WendyWhelan1');
INSERT INTO Actions (a_name, val)
VALUES ('Volunteer', 10), ('Donate', 5), ('Shout out', 1);
INSERT INTO Non_profits (np_name, np_email, np_pass, summary)
VALUES ('Happy Hounds', '[email protected]', 'hounds', 'This is a rescue shelter'),
('Teachers for Poughkeepsie', '[email protected]', '2345', 'This raises money for the teachers in Poughkeepsie.'),
('Food Shelter', '[email protected]', '1234', 'This is to encourage volunteers to contribute 10 hours.');
INSERT INTO Challenges (c_name, user_id, np_id)
VALUES ('Help Hounds', 3, 1),
('Volunteer 10', 4, 3),
('FundAClass', 1, 1),
('FundADog', 1, 2),
('FundAPet', 1, 3);
INSERT INTO ChallengeActions (c_id, a_id)
VALUES (1, 1),
(1, 3),
(2, 1),
(2, 2),
(3, 2),
(4, 2);
INSERT INTO UserParticipations(user_id, c_id, a_id, ContrVal)
VALUES (4, 1, 1, 10),
(1, 2, 1, 10),
(7, 2, 1, 10),
(9, 3, 2, 60),
(6, 3, 2, 7),
(3, 1, 3, 15),
(6, 4, 2, 12),
(5, 4, 2, 11),
(2, 4, 2, 1),
(4, 4, 2, 3);
INSERT INTO UserInvites(user_id1, user_id2, c_id)
VALUES (2, 4, 2),
(1, 8, 3),
(6, 3, 2),
(11, 10, 1),
(7, 4, 2),
(14, 12, 1),
(14, 1, 2),
(1, 8, 1),
(1, 6, 4),
(1, 5, 5),
(1, 2, 4),
(2, 4, 4),
(2, 7, 4),
(2, 3, 4),
(5, 8, 4),
(5, 10, 4),
(5, 11, 4),
(6, 9, 4),
(4, 7, 4);
/* Select * from UserInvite *//* s;
Select * from UserParticipation;
Select * from ChallengeActions;
select * from Actions;
select * from Challenges;
select * from Non_profits;
select * from Users;
Select * from
Select sum(contrval) from userpa *//* rticipation where c_id = 1 and a_id = 2 group by c_id, a_id; */