forked from eckama11/air_quality
-
Notifications
You must be signed in to change notification settings - Fork 0
/
air_quality.sql
56 lines (50 loc) · 1.59 KB
/
air_quality.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
DROP DATABASE IF EXISTS air_quality;
CREATE DATABASE air_quality;
USE air_quality;
Create TABLE sensors(
id INT NOT NULL AUTO_INCREMENT,
impId VARCHAR(50) NOT NULL,
timeInfo DATETIME NOT NULL,
temperature FLOAT NOT NULL,
humidity FLOAT NOT NULL,
pressure FLOAT NOT NULL,
altitude FLOAT NOT NULL,
latitude FLOAT NOT NULL,
longitude FLOAT NOT NULL,
particles FLOAT NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE user(
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
deviceId VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY username_deviceId(username, deviceId)
);
CREATE TABLE loginSession(
sessionId VARCHAR(255) NOT NULL,
authenticatedUser INT NOT NULL,
PRIMARY KEY(sessionID),
FOREIGN KEY(authenticatedUser) REFERENCES user(id)
);
-- Create the user which the app will use to connect to the DB
DROP PROCEDURE IF EXISTS air_quality.drop_user_if_exists ;
DELIMITER $$
CREATE PROCEDURE air_quality.drop_user_if_exists()
BEGIN
DECLARE foo BIGINT DEFAULT 0 ;
SELECT COUNT(*)
INTO foo
FROM mysql.user
WHERE User = 'air_quality' and Host = 'localhost';
IF foo > 0 THEN
DROP USER 'air_quality'@'localhost' ;
END IF;
END ;$$
DELIMITER ;
CALL air_quality.drop_user_if_exists() ;
DROP PROCEDURE IF EXISTS air_quality.drop_users_if_exists ;
CREATE USER 'air_quality'@'localhost' IDENTIFIED BY 'air_quality';
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE, LOCK TABLES, CREATE TEMPORARY TABLES ON air_quality.* TO 'air_quality'@'localhost';