-
Notifications
You must be signed in to change notification settings - Fork 1
/
initializeDatabase.php
200 lines (174 loc) · 5.17 KB
/
initializeDatabase.php
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
include 'includes/session.php';
include 'includes/dbConnect.php';
$query = 'CREATE TABLE users(
user_id INT NOT NULL AUTO_INCREMENT,
fb_id VARCHAR(100) UNIQUE DEFAULT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(63) DEFAULT NULL,
full_name VARCHAR(255) NOT NULL,
birth_date DATETIME DEFAULT NULL,
gender CHAR(1) DEFAULT NULL,
location VARCHAR(255) DEFAULT NULL,
last_login DATETIME DEFAULT NULL,
activated BOOLEAN NOT NULL DEFAULT 0,
activate_hash VARCHAR(63) DEFAULT NULL,
access_level INT NOT NULL DEFAULT 0,
PRIMARY KEY(user_id),
UNIQUE INDEX(email)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE users created succesfully.';
}
else {
echo 'Error in creating TABLE users.';
echo '<br>';
echo $result;
}
echo '<br>';
$query = 'CREATE TABLE meetings(
meeting_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
description VARCHAR(255) DEFAULT NULL,
finalized BOOLEAN NOT NULL DEFAULT 0,
location VARCHAR(255) DEFAULT NULL,
latitude FLOAT DEFAULT NULL,
longitude FLOAT DEFAULT NULL,
date_time DATETIME DEFAULT NULL,
PRIMARY KEY(meeting_id)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE meetings created succesfully.';
}
else {
echo 'Error in creating TABLE meetings.';
echo '<br>';
echo $result;
}
echo '<br>';
$query = 'CREATE TABLE meeting_users(
mu_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
meeting_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
user_confirmed BOOLEAN DEFAULT 0,
user_location_id INT UNSIGNED DEFAULT NULL,
PRIMARY KEY(mu_id)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE meeting_users created succesfully.';
}
else {
echo 'Error in creating TABLE meeting_users.';
echo '<br>';
echo $result;
}
echo '<br>';
$query = 'CREATE TABLE meeting_locations(
ml_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
meeting_id INT UNSIGNED NOT NULL,
location_id INT UNSIGNED NOT NULL,
num_votes INT UNSIGNED DEFAULT 1,
proposed_user_id INT UNSIGNED NOT NULL,
PRIMARY KEY(ml_id)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE meeting_locations created succesfully.';
}
else {
echo 'Error in creating TABLE meeting_locations.';
echo '<br>';
echo $result;
}
echo '<br>';
$query = 'CREATE TABLE locations(
location_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
description VARCHAR(255) DEFAULT NULL,
latitude FLOAT DEFAULT NULL,
longitude FLOAT DEFAULT NULL,
rating FLOAT DEFAULT 0,
num_rating INT DEFAULT 0,
PRIMARY KEY(location_id)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE locations created succesfully.';
}
else {
echo 'Error in creating TABLE locations.';
echo '<br>';
echo $result;
}
echo '<br>';
$query = 'CREATE TABLE mu_date_time(
mudt_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
mu_id INT UNSIGNED NOT NULL,
date_time DATETIME DEFAULT NULL,
PRIMARY KEY(mudt_id)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE mu_date_time created succesfully.';
}
else {
echo 'Error in creating TABLE mu_date_time.';
echo '<br>';
echo $result;
}
echo '<br>';
$query = 'CREATE TABLE feedbacks(
feedback_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
feedback VARCHAR(255) NOT NULL,
date_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(feedback_id)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE feedbacks created succesfully.';
}
else {
echo 'Error in creating TABLE feedbacks.';
echo '<br>';
echo $result;
}
echo '<br>';
$query = 'CREATE TABLE friendships(
friendship_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user1_id INT NOT NULL,
user2_id INT NOT NULL,
date_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(friendship_id)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE friendships created succesfully.';
}
else {
echo 'Error in creating TABLE friendships.';
echo '<br>';
echo $result;
}
echo '<br>';
$query = 'CREATE TABLE notifications(
notification_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL,
notification_message VARCHAR(255) NOT NULL,
notification_link VARCHAR(255) DEFAULT NULL,
notification_read BOOLEAN NOT NULL DEFAULT 0,
date_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(notification_id)
) ENGINE = INNODB';
$result = mysqli_query($connection, $query);
if ($result){
echo 'TABLE notifications created succesfully.';
}
else {
echo 'Error in creating TABLE notifications.';
echo '<br>';
echo $result;
}
?>