-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.sql
279 lines (232 loc) · 9.15 KB
/
db.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
-- This script was generated by the ERD tool in pgAdmin 4.
-- Please log an issue at https://github.com/pgadmin-org/pgadmin4/issues/new/choose if you find any bugs, including reproduction steps.
BEGIN;
CREATE TABLE IF NOT EXISTS public.account_identities
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
name character varying(100) COLLATE pg_catalog."default" NOT NULL,
identity_key character varying COLLATE pg_catalog."default",
identity_secret_key character varying COLLATE pg_catalog."default",
account_id uuid,
created_at timestamp without time zone,
updated_at timestamp without time zone,
key_size smallint NOT NULL,
key_type_id smallint,
CONSTRAINT account_identties_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.account_passwords
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
name character varying(250) COLLATE pg_catalog."default" NOT NULL,
content character varying COLLATE pg_catalog."default" NOT NULL,
account_id uuid NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone,
website character varying COLLATE pg_catalog."default",
CONSTRAINT account_passwords_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.account_secrets
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
name character varying(100) COLLATE pg_catalog."default" NOT NULL,
description character varying(300) COLLATE pg_catalog."default",
content character varying COLLATE pg_catalog."default" NOT NULL,
account_id uuid NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone,
website character varying COLLATE pg_catalog."default",
CONSTRAINT account_secrets_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.accounts
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
email character varying(200) COLLATE pg_catalog."default" NOT NULL,
subscription_id uuid,
account_type_id uuid,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone,
enabled boolean NOT NULL DEFAULT true,
CONSTRAINT accounts_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.associated_account_access_keys
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
account_id uuid NOT NULL,
access_key character varying(250) COLLATE pg_catalog."default" NOT NULL,
created_at timestamp without time zone NOT NULL,
name character varying COLLATE pg_catalog."default",
last_used_at timestamp without time zone,
device_type_id smallint,
CONSTRAINT associated_account_access_keys_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.device_types
(
id smallint NOT NULL,
name character varying(60) COLLATE pg_catalog."default",
CONSTRAINT device_types_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.event_types
(
id bigint NOT NULL,
name character varying(60) COLLATE pg_catalog."default",
CONSTRAINT event_types_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.events
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
description character varying COLLATE pg_catalog."default",
device_id uuid,
created_at timestamp without time zone NOT NULL,
event_type_id bigint NOT NULL,
CONSTRAINT events_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.key_types
(
id smallint NOT NULL,
name character varying(30) COLLATE pg_catalog."default",
description character varying(100) COLLATE pg_catalog."default",
has_size boolean DEFAULT true,
CONSTRAINT key_types_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.mfa_method_types
(
id smallint NOT NULL,
name character varying(100) COLLATE pg_catalog."default",
CONSTRAINT mfa_method_types_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.mfa_methods
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
type_id smallint NOT NULL,
value character varying COLLATE pg_catalog."default" NOT NULL,
user_id uuid NOT NULL,
address character varying COLLATE pg_catalog."default",
CONSTRAINT mfa_methods_pkey PRIMARY KEY (id, type_id, value)
);
CREATE TABLE IF NOT EXISTS public.rac_devices
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
name character varying(100) COLLATE pg_catalog."default" NOT NULL,
address character varying(40) COLLATE pg_catalog."default" NOT NULL,
key character varying COLLATE pg_catalog."default" NOT NULL,
created_by uuid NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone,
updated_by uuid,
CONSTRAINT rac_devices_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.subscriptions
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
created_at timestamp without time zone NOT NULL,
next_billing_date timestamp without time zone NOT NULL,
enabled boolean NOT NULL,
CONSTRAINT subscriptions_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.time_based_algorithms
(
id smallint NOT NULL,
name character varying(60) COLLATE pg_catalog."default",
CONSTRAINT time_based_algorithms_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.time_based_code_types
(
id smallint NOT NULL,
name character varying(60) COLLATE pg_catalog."default",
CONSTRAINT time_based_code_types_pkey PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.time_based_codes
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
website character varying(200) COLLATE pg_catalog."default" NOT NULL,
email character varying(200) COLLATE pg_catalog."default" NOT NULL,
secret character varying COLLATE pg_catalog."default" NOT NULL,
type_id smallint NOT NULL,
expiration smallint NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone,
algorithm_id smallint,
CONSTRAINT time_based_codes_pkey PRIMARY KEY (id)
);
ALTER TABLE IF EXISTS public.account_identities
ADD CONSTRAINT "account_Identities_account_id" FOREIGN KEY (account_id)
REFERENCES public.accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
ALTER TABLE IF EXISTS public.account_identities
ADD CONSTRAINT "account_Identities_key_type_id" FOREIGN KEY (key_type_id)
REFERENCES public.key_types (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.account_passwords
ADD CONSTRAINT account_passwords_account_id FOREIGN KEY (account_id)
REFERENCES public.accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
ALTER TABLE IF EXISTS public.account_secrets
ADD CONSTRAINT account_secrets_account_id FOREIGN KEY (account_id)
REFERENCES public.accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
ALTER TABLE IF EXISTS public.accounts
ADD CONSTRAINT accounts_subscription_id FOREIGN KEY (subscription_id)
REFERENCES public.subscriptions (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.associated_account_access_keys
ADD CONSTRAINT associated_account_access_keys_account_id FOREIGN KEY (account_id)
REFERENCES public.accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
ALTER TABLE IF EXISTS public.associated_account_access_keys
ADD CONSTRAINT associated_account_access_keys_device_type FOREIGN KEY (device_type_id)
REFERENCES public.device_types (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.events
ADD CONSTRAINT events_device_id FOREIGN KEY (device_id)
REFERENCES public.associated_account_access_keys (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
ALTER TABLE IF EXISTS public.events
ADD CONSTRAINT events_event_type_id FOREIGN KEY (event_type_id)
REFERENCES public.event_types (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.mfa_methods
ADD CONSTRAINT mfa_methods_type_id FOREIGN KEY (type_id)
REFERENCES public.mfa_method_types (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
ALTER TABLE IF EXISTS public.mfa_methods
ADD CONSTRAINT mfa_methods_user_id_fkey FOREIGN KEY (user_id)
REFERENCES public.accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.rac_devices
ADD CONSTRAINT rac_devices_created_by FOREIGN KEY (created_by)
REFERENCES public.accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
ALTER TABLE IF EXISTS public.rac_devices
ADD CONSTRAINT rac_updated_by FOREIGN KEY (updated_by)
REFERENCES public.accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
ALTER TABLE IF EXISTS public.time_based_codes
ADD CONSTRAINT time_based_code_algorithm_id FOREIGN KEY (algorithm_id)
REFERENCES public.time_based_algorithms (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.time_based_codes
ADD CONSTRAINT time_based_code_type_id FOREIGN KEY (type_id)
REFERENCES public.time_based_code_types (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
END;