-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sql
86 lines (77 loc) · 3.25 KB
/
setup.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
SET GLOBAL sql_mode="STRICT_TRANS_TABLES";
CREATE DATABASE IF NOT EXISTS lamp_controller;
USE lamp_controller;
CREATE TABLE IF NOT EXISTS user (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_name CHAR(32) NOT NULL UNIQUE,
display_name CHAR(32) NOT NULL,
password_hash CHAR(255) NOT NULL,
software_key CHAR(255) NOT NULL,
last_updated_at BIGINT UNSIGNED NOT NULL,
last_logdin_at BIGINT UNSIGNED NOT NULL,
flag INT UNSIGNED DEFAULT 0 NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS directory (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
parent_id BIGINT,
user_id INT UNSIGNED NOT NULL,
flag INT UNSIGNED DEFAULT 0 NOT NULL,
INDEX(parent_id),
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS file (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
directory_id BIGINT NOT NULL,
flag INT UNSIGNED DEFAULT 0 NOT NULL,
INDEX(directory_id),
FOREIGN KEY (directory_id) REFERENCES directory (id) ON DELETE CASCADE)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS software (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
drive_serial_no INT NOT NULL,
pc_name CHAR(100) NOT NULL,
entered_at BIGINT NOT NULL,
user_id INT UNSIGNED NOT NULL,
display_name CHAR(32) NOT NULL,
flag INT UNSIGNED NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS send_queue (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
milli_time BIGINT NOT NULL,
software_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
json TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE,
FOREIGN KEY (software_id) REFERENCES software (id) ON DELETE CASCADE)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS receive (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
software_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
time BIGINT NOT NULL,
json TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE,
FOREIGN KEY (software_id) REFERENCES software (id) ON DELETE CASCADE)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS session (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
session_id CHAR(255) NOT NULL UNIQUE,
user_id INT UNSIGNED NOT NULL,
type TINYINT UNSIGNED NOT NULL,
last_logdin_at BIGINT UNSIGNED NOT NULL,
flag INT UNSIGNED DEFAULT 0 NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS guest (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
guest_id CHAR(255) NOT NULL UNIQUE,
display_name CHAR(32) NOT NULL,
user_id INT UNSIGNED NOT NULL,
software_id INT UNSIGNED NOT NULL,
flag INT UNSIGNED DEFAULT 0 NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE,
FOREIGN KEY (software_id) REFERENCES software (id) ON DELETE CASCADE)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;