-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhoami.sql
More file actions
60 lines (55 loc) · 1.7 KB
/
whoami.sql
File metadata and controls
60 lines (55 loc) · 1.7 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
-- WHOAMI Database Schema
-- Users table
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
email TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
-- Roles table
CREATE TABLE IF NOT EXISTS roles (
id TEXT PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
description TEXT,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
-- Policies table
CREATE TABLE IF NOT EXISTS policies (
id TEXT PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
description TEXT,
document TEXT NOT NULL,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
-- User-Role junction table
CREATE TABLE IF NOT EXISTS user_roles (
user_id TEXT NOT NULL,
role_id TEXT NOT NULL,
created_at TEXT NOT NULL,
PRIMARY KEY (user_id, role_id),
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (role_id) REFERENCES roles (id) ON DELETE CASCADE
);
-- Role-Policy junction table
CREATE TABLE IF NOT EXISTS role_policies (
role_id TEXT NOT NULL,
policy_id TEXT NOT NULL,
created_at TEXT NOT NULL,
PRIMARY KEY (role_id, policy_id),
FOREIGN KEY (role_id) REFERENCES roles (id) ON DELETE CASCADE,
FOREIGN KEY (policy_id) REFERENCES policies (id) ON DELETE CASCADE
);
-- User-Policy junction table (direct policy assignment)
CREATE TABLE IF NOT EXISTS user_policies (
user_id TEXT NOT NULL,
policy_id TEXT NOT NULL,
created_at TEXT NOT NULL,
PRIMARY KEY (user_id, policy_id),
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (policy_id) REFERENCES policies (id) ON DELETE CASCADE
);