-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
469 lines (322 loc) · 11.3 KB
/
Copy pathschema.sql
File metadata and controls
469 lines (322 loc) · 11.3 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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
--
-- PostgreSQL database dump
--
\restrict pIT2EI3DAwl6M92sx6PJ2Ykeoy4UzqxYdSYR8LMncOzSbBzlOF8ho5j57o0UITE
-- Dumped from database version 15.14 (Debian 15.14-1.pgdg13+1)
-- Dumped by pg_dump version 15.14 (Debian 15.14-1.pgdg13+1)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
--
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';
--
-- Name: app_status; Type: TYPE; Schema: public; Owner: sso_admin
--
CREATE TYPE public.app_status AS ENUM (
'active',
'inactive',
'blocked',
'deleted',
'unverified'
);
ALTER TYPE public.app_status OWNER TO sso_admin;
--
-- Name: available_fields; Type: TYPE; Schema: public; Owner: sso_admin
--
CREATE TYPE public.available_fields AS ENUM (
'email',
'username',
'language',
'theme',
'profile_pic',
'date_of_birth',
'gender',
'phone_numbers',
'addresses',
'full_name',
'preferred_first_name'
);
ALTER TYPE public.available_fields OWNER TO sso_admin;
--
-- Name: gender; Type: TYPE; Schema: public; Owner: sso_admin
--
CREATE TYPE public.gender AS ENUM (
'male',
'female',
'other',
'prefer not to say'
);
ALTER TYPE public.gender OWNER TO sso_admin;
--
-- Name: language; Type: TYPE; Schema: public; Owner: sso_admin
--
CREATE TYPE public.language AS ENUM (
'en'
);
ALTER TYPE public.language OWNER TO sso_admin;
--
-- Name: theme; Type: TYPE; Schema: public; Owner: sso_admin
--
CREATE TYPE public.theme AS ENUM (
'light',
'dark',
'automatic',
'app-default'
);
ALTER TYPE public.theme OWNER TO sso_admin;
--
-- Name: user_status; Type: TYPE; Schema: public; Owner: sso_admin
--
CREATE TYPE public.user_status AS ENUM (
'active',
'inactive',
'deleted',
'unverified'
);
ALTER TYPE public.user_status OWNER TO sso_admin;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: addresses; Type: TABLE; Schema: public; Owner: sso_admin
--
CREATE TABLE public.addresses (
id uuid DEFAULT gen_random_uuid() NOT NULL,
user_id uuid,
line1 character varying NOT NULL,
line2 character varying,
city character varying,
state character varying,
postal_code character varying,
country character varying,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
default_address boolean
);
ALTER TABLE public.addresses OWNER TO sso_admin;
--
-- Name: apps; Type: TABLE; Schema: public; Owner: sso_admin
--
CREATE TABLE public.apps (
id uuid DEFAULT gen_random_uuid() NOT NULL,
client_name text NOT NULL,
scopes public.available_fields[] DEFAULT ARRAY['email'::public.available_fields],
created_at timestamp without time zone DEFAULT now(),
status public.app_status DEFAULT 'unverified'::public.app_status,
secret text,
logo text,
CONSTRAINT apps_scopes_check CHECK (('email'::public.available_fields = ANY (scopes)))
);
ALTER TABLE public.apps OWNER TO sso_admin;
--
-- Name: otp; Type: TABLE; Schema: public; Owner: sso_admin
--
CREATE TABLE public.otp (
id uuid DEFAULT gen_random_uuid() NOT NULL,
user_id uuid,
code character(6) NOT NULL,
created_at timestamp without time zone DEFAULT now(),
expires_at timestamp without time zone DEFAULT (now() + '00:10:00'::interval)
);
ALTER TABLE public.otp OWNER TO sso_admin;
--
-- Name: phones; Type: TABLE; Schema: public; Owner: sso_admin
--
CREATE TABLE public.phones (
id uuid NOT NULL,
user_id uuid,
country_code text NOT NULL,
number text NOT NULL,
verified boolean DEFAULT false,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
default_phone boolean
);
ALTER TABLE public.phones OWNER TO sso_admin;
--
-- Name: refresh_tokens; Type: TABLE; Schema: public; Owner: sso_admin
--
CREATE TABLE public.refresh_tokens (
id uuid DEFAULT gen_random_uuid() NOT NULL,
token text NOT NULL,
user_id uuid NOT NULL,
app_id uuid,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
expires_at timestamp without time zone DEFAULT (CURRENT_TIMESTAMP + '30 days'::interval) NOT NULL
);
ALTER TABLE public.refresh_tokens OWNER TO sso_admin;
--
-- Name: usernames; Type: TABLE; Schema: public; Owner: sso_admin
--
CREATE TABLE public.usernames (
id uuid DEFAULT gen_random_uuid() NOT NULL,
user_id uuid NOT NULL,
current boolean NOT NULL,
username text NOT NULL,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE public.usernames OWNER TO sso_admin;
--
-- Name: users; Type: TABLE; Schema: public; Owner: sso_admin
--
CREATE TABLE public.users (
id uuid DEFAULT gen_random_uuid() NOT NULL,
email text NOT NULL,
password text NOT NULL,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
status public.user_status DEFAULT 'unverified'::public.user_status,
profile_pic text,
language public.language DEFAULT 'en'::public.language,
theme public.theme DEFAULT 'app-default'::public.theme,
date_of_birth date,
gender public.gender,
full_name text,
preferred_first_name text
);
ALTER TABLE public.users OWNER TO sso_admin;
--
-- Data for Name: addresses; Type: TABLE DATA; Schema: public; Owner: sso_admin
--
COPY public.addresses (id, user_id, line1, line2, city, state, postal_code, country, created_at, default_address) FROM stdin;
\.
--
-- Data for Name: apps; Type: TABLE DATA; Schema: public; Owner: sso_admin
--
COPY public.apps (id, client_name, scopes, created_at, status, secret, logo) FROM stdin;
a0f9ce02-f29a-40ce-abe5-b23fdc9fed87 DevUs AMS {email,username,language,theme,profile_pic,date_of_birth,gender,phone_numbers,addresses,full_name,preferred_first_name} 2025-11-14 20:35:16.308948 active 48a3d9e0b12d1d0b6a85baff38fa72e03ed7f6b0d0f50658369719057fd0f2f6 \N
\.
--
-- Data for Name: otp; Type: TABLE DATA; Schema: public; Owner: sso_admin
--
COPY public.otp (id, user_id, code, created_at, expires_at) FROM stdin;
\.
--
-- Data for Name: phones; Type: TABLE DATA; Schema: public; Owner: sso_admin
--
COPY public.phones (id, user_id, country_code, number, verified, created_at, default_phone) FROM stdin;
\.
--
-- Data for Name: refresh_tokens; Type: TABLE DATA; Schema: public; Owner: sso_admin
--
COPY public.refresh_tokens (id, token, user_id, app_id, created_at, expires_at) FROM stdin;
\.
--
-- Data for Name: usernames; Type: TABLE DATA; Schema: public; Owner: sso_admin
--
COPY public.usernames (id, user_id, current, username, created_at) FROM stdin;
\.
--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: sso_admin
--
COPY public.users (id, email, password, created_at, status, profile_pic, language, theme, date_of_birth, gender, full_name, preferred_first_name) FROM stdin;
\.
--
-- Name: addresses addresses_pkey; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.addresses
ADD CONSTRAINT addresses_pkey PRIMARY KEY (id);
--
-- Name: apps apps_client_name_key; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.apps
ADD CONSTRAINT apps_client_name_key UNIQUE (client_name);
--
-- Name: apps apps_pkey; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.apps
ADD CONSTRAINT apps_pkey PRIMARY KEY (id);
--
-- Name: otp otp_pkey; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.otp
ADD CONSTRAINT otp_pkey PRIMARY KEY (id);
--
-- Name: phones phones_pkey; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.phones
ADD CONSTRAINT phones_pkey PRIMARY KEY (id);
--
-- Name: refresh_tokens refresh_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.refresh_tokens
ADD CONSTRAINT refresh_tokens_pkey PRIMARY KEY (id);
--
-- Name: refresh_tokens refresh_tokens_token_key; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.refresh_tokens
ADD CONSTRAINT refresh_tokens_token_key UNIQUE (token);
--
-- Name: usernames usernames_pkey; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.usernames
ADD CONSTRAINT usernames_pkey PRIMARY KEY (id);
--
-- Name: usernames usernames_username_key; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.usernames
ADD CONSTRAINT usernames_username_key UNIQUE (username);
--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
--
-- Name: unique_active_email; Type: INDEX; Schema: public; Owner: sso_admin
--
CREATE UNIQUE INDEX unique_active_email ON public.users USING btree (email) WHERE (status <> 'deleted'::public.user_status);
--
-- Name: unique_current_username_per_user; Type: INDEX; Schema: public; Owner: sso_admin
--
CREATE UNIQUE INDEX unique_current_username_per_user ON public.usernames USING btree (user_id) WHERE (current = true);
--
-- Name: unique_default_address_per_user; Type: INDEX; Schema: public; Owner: sso_admin
--
CREATE UNIQUE INDEX unique_default_address_per_user ON public.addresses USING btree (user_id) WHERE (default_address = true);
--
-- Name: unique_default_phone_per_user; Type: INDEX; Schema: public; Owner: sso_admin
--
CREATE UNIQUE INDEX unique_default_phone_per_user ON public.phones USING btree (user_id) WHERE (default_phone = true);
--
-- Name: addresses addresses_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.addresses
ADD CONSTRAINT addresses_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
--
-- Name: otp otp_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.otp
ADD CONSTRAINT otp_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
--
-- Name: phones phones_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.phones
ADD CONSTRAINT phones_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
--
-- Name: refresh_tokens refresh_tokens_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.refresh_tokens
ADD CONSTRAINT refresh_tokens_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id) ON DELETE CASCADE;
--
-- Name: refresh_tokens refresh_tokens_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.refresh_tokens
ADD CONSTRAINT refresh_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
--
-- Name: usernames usernames_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: sso_admin
--
ALTER TABLE ONLY public.usernames
ADD CONSTRAINT usernames_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
--
-- PostgreSQL database dump complete
--
\unrestrict pIT2EI3DAwl6M92sx6PJ2Ykeoy4UzqxYdSYR8LMncOzSbBzlOF8ho5j57o0UITE