-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.sql
45 lines (42 loc) · 1.3 KB
/
tables.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
-- Users Table
CREATE TABLE users (
user_id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
sustainability_score INT DEFAULT 0,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
-- Environmental Data Table
CREATE TABLE environmental_data (
data_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
data_type VARCHAR(255) NOT NULL,
value FLOAT NOT NULL,
timestamp TIMESTAMP NOT NULL,
location VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW(),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
-- Alerts Table
CREATE TABLE alerts (
alert_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
message TEXT NOT NULL,
threshold FLOAT NOT NULL,
timestamp TIMESTAMP NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
-- Community Reports Table
CREATE TABLE community_reports (
report_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
issue_type VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
timestamp TIMESTAMP NOT NULL,
location VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW(),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);