-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcasmi.sql
94 lines (78 loc) · 2.14 KB
/
casmi.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
87
88
89
90
91
92
93
94
CREATE TABLE providers (
id INT NOT NULL AUTO_INCREMENT,
code VARCHAR(3) NOT NULL,
public_name VARCHAR(50) NOT NULL,
PRIMARY KEY (id),
UNIQUE (code)
);
INSERT INTO providers
(code, public_name)
VALUES
('aws', 'Amazon Web Services'),
('azr', 'Microsoft Azure'),
('gcp', 'Google Cloud Platform');
CREATE TABLE secrets (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
vault_key VARCHAR(200) NOT NULL,
PRIMARY KEY (id),
UNIQUE (vault_key)
);
INSERT INTO secrets
(name, vault_key)
VALUES
('default', 'secret/data/casmi/default');
CREATE TABLE spaces (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
secret_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (secret_id) REFERENCES secrets(id),
UNIQUE (name)
);
CREATE TABLE space_provider (
id INT NOT NULL AUTO_INCREMENT,
space_id INT NOT NULL,
provider_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (space_id) REFERENCES spaces(id),
FOREIGN KEY (provider_id) REFERENCES providers(id),
CONSTRAINT unique_store_provider UNIQUE (space_id, provider_id)
);
CREATE TABLE stores (
id INT NOT NULL AUTO_INCREMENT,
file_count INT NOT NULL,
space_id INT NOT NULL,
provider_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (space_id) REFERENCES spaces(id),
FOREIGN KEY (provider_id) REFERENCES providers(id)
);
CREATE TABLE folders (
id INT NOT NULL AUTO_INCREMENT,
provider_key VARCHAR(200) NOT NULL,
store_id INT NOT NULL,
space_id INT NOT NULL,
provider_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (store_id) REFERENCES stores(id),
FOREIGN KEY (space_id) REFERENCES spaces(id),
FOREIGN KEY (provider_id) REFERENCES providers(id),
CONSTRAINT unique_store_folders UNIQUE (provider_key, store_id)
);
CREATE TABLE files (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
size BIGINT NOT NULL,
provider_key VARCHAR(200) NOT NULL,
folder_id INT NOT NULL,
store_id INT NOT NULL,
space_id INT NOT NULL,
provider_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (folder_id) REFERENCES folders(id),
FOREIGN KEY (store_id) REFERENCES stores(id),
FOREIGN KEY (space_id) REFERENCES spaces(id),
FOREIGN KEY (provider_id) REFERENCES providers(id),
CONSTRAINT unique_store_files UNIQUE (provider_key, store_id)
);