forked from bijomaru78/eccm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.sql
More file actions
82 lines (74 loc) · 3.45 KB
/
database.sql
File metadata and controls
82 lines (74 loc) · 3.45 KB
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
-- ============================================================
-- ECCM – Ethernet Cable Connection Manager
-- MySQL Database Schema v2 (with permissions)
-- ============================================================
CREATE DATABASE IF NOT EXISTS eccm_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE eccm_db;
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role ENUM('admin','user') NOT NULL DEFAULT 'user',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS password_resets (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
token VARCHAR(64) NOT NULL UNIQUE,
expires_at DATETIME NOT NULL,
used TINYINT(1) NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS profiles (
id INT AUTO_INCREMENT PRIMARY KEY,
owner_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
data LONGTEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY uq_owner_profile (owner_id, name)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS profile_permissions (
id INT AUTO_INCREMENT PRIMARY KEY,
profile_id INT NOT NULL,
user_id INT NOT NULL,
can_view TINYINT(1) NOT NULL DEFAULT 1,
can_patch TINYINT(1) NOT NULL DEFAULT 0,
can_add_patch TINYINT(1) NOT NULL DEFAULT 0,
can_edit_device TINYINT(1) NOT NULL DEFAULT 0,
can_add_device TINYINT(1) NOT NULL DEFAULT 0,
can_delete TINYINT(1) NOT NULL DEFAULT 0,
can_manage TINYINT(1) NOT NULL DEFAULT 0,
can_export TINYINT(1) NOT NULL DEFAULT 0,
can_backup TINYINT(1) NOT NULL DEFAULT 0,
FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY uq_profile_user (profile_id, user_id)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS user_active_profile (
user_id INT PRIMARY KEY,
profile_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS user_settings (
user_id INT PRIMARY KEY,
settings TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS notification_subscriptions (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
profile_id INT NOT NULL,
on_device_change TINYINT(1) NOT NULL DEFAULT 0,
on_device_add TINYINT(1) NOT NULL DEFAULT 0,
on_patch_change TINYINT(1) NOT NULL DEFAULT 0,
on_patch_add TINYINT(1) NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE,
UNIQUE KEY uq_user_profile_notif (user_id, profile_id)
) ENGINE=InnoDB;