-
Notifications
You must be signed in to change notification settings - Fork 61
/
lbstarter.dbs
505 lines (493 loc) · 24.2 KB
/
lbstarter.dbs
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<?xml version="1.0" encoding="UTF-8" ?>
<project name="PostgreSQL" id="Project_2cbf47" database="PostgreSQL" >
<schema name="lbstarter" >
<table name="auth_clients" >
<column name="id" type="integer" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<column name="client_id" type="varchar" length="50" jt="12" mandatory="y" />
<column name="client_secret" type="varchar" length="50" jt="12" mandatory="y" />
<column name="redirect_url" type="varchar" length="200" jt="12" />
<column name="access_token_expiration" type="integer" jt="4" mandatory="y" >
<defo><![CDATA[900]]></defo>
</column>
<column name="refresh_token_expiration" type="integer" jt="4" mandatory="y" >
<defo><![CDATA[86400]]></defo>
</column>
<column name="auth_code_expiration" type="integer" jt="4" mandatory="y" >
<defo><![CDATA[180]]></defo>
</column>
<column name="secret" type="varchar" length="50" jt="12" mandatory="y" />
<column name="created_on" type="timestamptz" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="modified_on" type="timestamptz" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted" type="boolean" jt="16" mandatory="y" >
<defo><![CDATA[false]]></defo>
</column>
<column name="user_ids" type="integer[]" length="10" decimal="0" jt="2003" />
<column name="deleted_on" type="timestamp" jt="93" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted_by" type="varchar" length="200" jt="12" />
<index name="pk_auth_clients_id" unique="PRIMARY_KEY" >
<column name="id" />
</index>
</table>
<table name="roles" >
<column name="id" type="integer" length="10" decimal="0" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<column name="name" type="varchar" length="100" decimal="0" jt="12" mandatory="y" />
<column name="created_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="modified_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted" type="boolean" length="1" decimal="0" jt="16" mandatory="y" >
<defo><![CDATA[false]]></defo>
</column>
<column name="permissions" type="text[]" decimal="0" jt="2003" />
<column name="role_key" type="integer" jt="4" mandatory="y" />
<column name="deleted_on" type="timestamp" jt="93" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted_by" type="varchar" length="200" jt="12" />
<index name="pk_roles_id" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<index name="idx_roles_key" unique="NORMAL" >
<column name="role_key" />
</index>
</table>
<table name="tenants" >
<column name="id" type="integer" length="10" decimal="0" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<column name="name" type="varchar" length="100" decimal="0" jt="12" mandatory="y" />
<column name="type" type="varchar" length="50" decimal="0" jt="12" mandatory="y" />
<column name="created_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="modified_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="created_by" type="integer" length="10" decimal="0" jt="4" />
<column name="modified_by" type="integer" length="10" decimal="0" jt="4" />
<column name="deleted" type="boolean" length="1" decimal="0" jt="16" mandatory="y" >
<defo><![CDATA[false]]></defo>
</column>
<column name="address1" type="varchar" length="100" decimal="0" jt="12" />
<column name="address2" type="varchar" length="100" decimal="0" jt="12" />
<column name="address3" type="varchar" length="100" decimal="0" jt="12" />
<column name="address4" type="varchar" length="100" decimal="0" jt="12" />
<column name="city" type="varchar" length="100" decimal="0" jt="12" />
<column name="state" type="varchar" length="100" decimal="0" jt="12" />
<column name="zip" type="varchar" length="20" decimal="0" jt="12" />
<column name="country" type="varchar" length="50" decimal="0" jt="12" />
<column name="status" type="varchar" length="50" jt="12" mandatory="y" >
<defo><![CDATA['active'::character varying]]></defo>
</column>
<column name="deleted_on" type="timestamp" jt="93" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted_by" type="varchar" length="200" jt="12" />
<index name="pk_tenant_id" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<index name="idx_tenants_created_by" unique="NORMAL" >
<column name="created_by" />
</index>
<index name="idx_tenants_modified_by" unique="NORMAL" >
<column name="modified_by" />
</index>
<fk name="fk_created_by" to_schema="lbstarter" to_table="user_tenants" >
<fk_column name="created_by" pk="id" />
</fk>
<fk name="fk_modified_by" to_schema="lbstarter" to_table="user_tenants" >
<fk_column name="modified_by" pk="id" />
</fk>
</table>
<table name="user_credentials" >
<column name="id" type="integer" length="10" decimal="0" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<column name="user_id" type="integer" length="10" decimal="0" jt="4" mandatory="y" />
<column name="auth_provider" type="varchar" length="50" decimal="0" jt="12" mandatory="y" />
<column name="auth_id" type="varchar" length="100" decimal="0" jt="12" />
<column name="auth_token" type="varchar" length="100" decimal="0" jt="12" />
<column name="password" type="varchar" length="60" decimal="0" jt="12" />
<column name="created_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="modified_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted" type="boolean" length="1" decimal="0" jt="16" mandatory="y" >
<defo><![CDATA[false]]></defo>
</column>
<column name="deleted_on" type="timestamp" jt="93" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted_by" type="varchar" length="200" jt="12" />
<index name="pk_user_credentials_id" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<index name="idx_user_credentials_user_id" unique="UNIQUE_KEY" >
<column name="user_id" />
</index>
<index name="idx_user_credentials" unique="NORMAL" >
<column name="auth_provider" />
</index>
<fk name="fk_user_credentials_users" to_schema="lbstarter" to_table="users" >
<fk_column name="user_id" pk="id" />
</fk>
</table>
<table name="user_tenant_permissions" >
<column name="id" type="integer" length="10" decimal="0" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<column name="user_tenant_id" type="integer" length="10" decimal="0" jt="4" mandatory="y" />
<column name="created_on" type="date" length="13" decimal="0" jt="91" mandatory="y" >
<defo><![CDATA[CURRENT_DATE]]></defo>
</column>
<column name="modified_on" type="date" length="13" decimal="0" jt="91" mandatory="y" >
<defo><![CDATA[CURRENT_DATE]]></defo>
</column>
<column name="created_by" type="integer" length="10" decimal="0" jt="4" />
<column name="modified_by" type="integer" length="10" decimal="0" jt="4" />
<column name="deleted" type="boolean" length="1" decimal="0" jt="16" mandatory="y" >
<defo><![CDATA[false]]></defo>
</column>
<column name="permission" type="text" decimal="0" jt="12" mandatory="y" />
<column name="allowed" type="boolean" length="1" decimal="0" jt="16" mandatory="y" >
<defo><![CDATA[true]]></defo>
</column>
<column name="deleted_on" type="timestamp" jt="93" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted_by" type="varchar" length="200" jt="12" />
<index name="pk_user_permissions_id" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<index name="idx_user_tenant_permissions_created_by" unique="NORMAL" >
<column name="created_by" />
</index>
<index name="idx_user_tenant_permissions_modified_by" unique="NORMAL" >
<column name="modified_by" />
</index>
<index name="idx_user_tenant_permissions_user_tenant_id" unique="NORMAL" >
<column name="user_tenant_id" />
</index>
<fk name="fk_created_by" to_schema="lbstarter" to_table="user_tenants" >
<fk_column name="created_by" pk="id" />
</fk>
<fk name="fk_modified_by" to_schema="lbstarter" to_table="user_tenants" >
<fk_column name="modified_by" pk="id" />
</fk>
<fk name="fk_user_tenant_permissions" to_schema="lbstarter" to_table="user_tenants" >
<fk_column name="user_tenant_id" pk="id" />
</fk>
</table>
<table name="user_tenants" >
<column name="id" type="integer" length="10" decimal="0" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<column name="user_id" type="integer" length="10" decimal="0" jt="4" mandatory="y" />
<column name="tenant_id" type="integer" length="10" decimal="0" jt="4" mandatory="y" />
<column name="created_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="modified_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted" type="boolean" length="1" decimal="0" jt="16" mandatory="y" >
<defo><![CDATA[false]]></defo>
</column>
<column name="role_id" type="integer" length="10" decimal="0" jt="4" mandatory="y" />
<column name="status" type="varchar" length="50" decimal="0" jt="12" mandatory="y" >
<defo><![CDATA['active'::character varying]]></defo>
</column>
<column name="deleted_on" type="timestamp" jt="93" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="deleted_by" type="varchar" length="200" jt="12" />
<index name="pk_user_tenant_id" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<index name="idx_user_tenant_tenant_id" unique="NORMAL" >
<column name="tenant_id" />
</index>
<index name="idx_user_tenant_user_id" unique="NORMAL" >
<column name="user_id" />
</index>
<index name="idx_user_tenants_role_id" unique="NORMAL" >
<column name="role_id" />
</index>
<fk name="fk_user_tenants_roles" to_schema="lbstarter" to_table="roles" >
<fk_column name="role_id" pk="id" />
</fk>
<fk name="fk_user_tenant_tenant" to_schema="lbstarter" to_table="tenants" >
<fk_column name="tenant_id" pk="id" />
</fk>
<fk name="fk_user_tenant_user" to_schema="lbstarter" to_table="users" >
<fk_column name="user_id" pk="id" />
</fk>
</table>
<table name="users" >
<column name="id" type="integer" length="10" decimal="0" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<column name="first_name" type="varchar" length="50" decimal="0" jt="12" mandatory="y" />
<column name="middle_name" type="varchar" length="50" decimal="0" jt="12" />
<column name="last_name" type="varchar" length="50" decimal="0" jt="12" />
<column name="username" type="varchar" length="150" decimal="0" jt="12" mandatory="y" />
<column name="email" type="varchar" length="150" decimal="0" jt="12" />
<column name="phone" type="varchar" length="15" decimal="0" jt="12" />
<column name="created_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="modified_on" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
</column>
<column name="created_by" type="integer" length="10" decimal="0" jt="4" />
<column name="modified_by" type="integer" length="10" decimal="0" jt="4" />
<column name="deleted" type="boolean" length="1" decimal="0" jt="16" mandatory="y" >
<defo><![CDATA[false]]></defo>
</column>
<column name="default_tenant" type="integer" length="10" decimal="0" jt="4" mandatory="y" />
<column name="last_login" type="timestamptz" length="35" decimal="6" jt="93" />
<column name="deleted_on" type="timestamp" jt="93" />
<column name="deleted_by" type="varchar" length="200" jt="12" />
<index name="pk_user_id" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<index name="idx_username" unique="UNIQUE_KEY" >
<column name="username" />
</index>
<index name="idx_user_created_by" unique="NORMAL" >
<column name="created_by" />
</index>
<index name="idx_user_modified_by" unique="NORMAL" >
<column name="modified_by" />
</index>
<index name="idx_users_default_tenant" unique="NORMAL" >
<column name="default_tenant" />
</index>
<fk name="fk_users_tenants_default_tenant" to_schema="lbstarter" to_table="tenants" >
<fk_column name="default_tenant" pk="id" />
</fk>
<fk name="fk_user_user_tenant_created_by" to_schema="lbstarter" to_table="user_tenants" >
<fk_column name="created_by" pk="id" />
</fk>
<fk name="fk_user_user_tenant_modified_by" to_schema="lbstarter" to_table="user_tenants" >
<fk_column name="modified_by" pk="id" />
</fk>
</table>
<sequence name="auth_clients_id_seq" />
<sequence name="roles_id_seq" />
<sequence name="roles_id_seq1" />
<sequence name="tenants_id_seq" />
<sequence name="tenants_id_seq1" />
<sequence name="user_credentials_id_seq" />
<sequence name="user_tenant_permissions_id_seq" />
<sequence name="user_tenant_permissions_id_seq1" />
<sequence name="user_tenants_id_seq" />
<sequence name="user_tenants_id_seq1" />
<sequence name="users_id_seq" />
<sequence name="users_id_seq1" />
<trigger name="mdt_roles" table="roles" id="Trigger_377b014" isSystem="false" >
<string><![CDATA[CREATE TRIGGER mdt_roles BEFORE UPDATE ON lbstarter.roles FOR EACH ROW EXECUTE PROCEDURE moddatetime();]]></string>
</trigger>
<trigger name="mdt_tenants" table="tenants" id="Trigger_1513b2f" isSystem="false" >
<string><![CDATA[CREATE TRIGGER mdt_tenants BEFORE UPDATE ON lbstarter.tenants FOR EACH ROW EXECUTE PROCEDURE moddatetime();]]></string>
</trigger>
<trigger name="mdt_user_tenant_permissions" table="user_tenant_permissions" id="Trigger_3f13971" isSystem="false" >
<string><![CDATA[CREATE TRIGGER mdt_user_tenant_permissions BEFORE UPDATE ON lbstarter.user_tenant_permissions FOR EACH ROW EXECUTE PROCEDURE moddatetime();]]></string>
</trigger>
<trigger name="mdt_user_tenants" table="user_tenants" id="Trigger_50de6bb" isSystem="false" >
<string><![CDATA[CREATE TRIGGER mdt_user_tenants BEFORE UPDATE ON lbstarter.user_tenants FOR EACH ROW EXECUTE PROCEDURE moddatetime();]]></string>
</trigger>
<trigger name="mdt_users" table="users" id="Trigger_47ba329" isSystem="false" >
<string><![CDATA[CREATE TRIGGER mdt_users BEFORE UPDATE ON lbstarter.users FOR EACH ROW EXECUTE PROCEDURE moddatetime();]]></string>
</trigger>
<trigger name="tenants_audit_trigger" table="tenants" id="Trigger_2c99451" isSystem="false" >
<string><![CDATA[CREATE TRIGGER tenants_audit_trigger AFTER INSERT OR DELETE OR UPDATE ON lbstarter.tenants FOR EACH ROW EXECUTE PROCEDURE logs.audit_trigger('USER_LOGS');]]></string>
</trigger>
<trigger name="user_tenant_permissions_audit_trigger" table="user_tenant_permissions" id="Trigger_45615d" isSystem="false" >
<string><![CDATA[CREATE TRIGGER user_tenant_permissions_audit_trigger AFTER INSERT OR DELETE OR UPDATE ON lbstarter.user_tenant_permissions FOR EACH ROW EXECUTE PROCEDURE logs.audit_trigger('USER_LOGS');]]></string>
</trigger>
<trigger name="users_audit_trigger" table="users" id="Trigger_29c08a1" isSystem="false" >
<string><![CDATA[CREATE TRIGGER users_audit_trigger AFTER INSERT OR DELETE OR UPDATE ON lbstarter.users FOR EACH ROW EXECUTE PROCEDURE logs.audit_trigger('USER_LOGS');]]></string>
</trigger>
</schema>
<schema name="public" catalogname="lbstarter" >
<table name="migrations" >
<column name="id" type="serial" length="10" decimal="0" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<column name="name" type="varchar" length="255" decimal="0" jt="12" mandatory="y" />
<column name="run_on" type="timestamp" length="29" decimal="6" jt="93" mandatory="y" />
<index name="migrations_pkey" unique="PRIMARY_KEY" >
<column name="id" />
</index>
</table>
<sequence name="migrations_id_seq" />
<procedure name="moddatetime" id="Procedure_4f4e99" isSystem="false" params_known="y" >
<string><![CDATA[CREATE OR REPLACE FUNCTION public.moddatetime()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
NEW.modified_on = now();
RETURN NEW;
END;
$function$
;]]></string>
<result_param name="returnValue" jt="1111" type="trigger" />
</procedure>
</schema>
<schema name="logs" >
<table name="audit_logs" >
<column name="operation_name" type="varchar" length="10" decimal="0" jt="12" mandatory="y" />
<column name="operation_time" type="timestamptz" length="35" decimal="6" jt="93" mandatory="y" >
<defo><![CDATA[now()]]></defo>
</column>
<column name="table_name" type="varchar" length="60" decimal="0" jt="12" mandatory="y" />
<column name="log_type" type="varchar" length="100" decimal="0" jt="12" >
<defo><![CDATA['APPLICATION_LOGS'::character varying]]></defo>
</column>
<column name="entity_id" type="varchar" decimal="0" jt="12" />
<column name="user_id" type="varchar" decimal="0" jt="12" />
<column name="before" type="jsonb" decimal="0" jt="2000" />
<column name="after" type="jsonb" decimal="0" jt="2000" />
<column name="id" type="integer" jt="4" mandatory="y" >
<identity><![CDATA[GENERATED {BY DEFAULT|ALWAYS} AS IDENTITY [(AS ~dataType~ |INCREMENT BY ~increment~ |MINVALUE ~minvalue~ |NO MINVALUE |MAXVALUE ~maxvalue~ |NO MAXVALUE |START WITH ~start~ |CACHE ~cache~ |CYCLE |OWNED BY ~tableDotColumn~ )] |GENERATED ALWAYS AS ( ~generation_expr~ ) [STORED]]]></identity>
</column>
<index name="pk_audit_logs_id" unique="PRIMARY_KEY" >
<column name="id" />
</index>
</table>
<sequence name="audit_logs_id_seq" />
<sequence name="audit_logs_id_seq1" />
<procedure name="audit_trigger" id="Procedure_133635" isSystem="false" params_known="y" >
<string><![CDATA[CREATE OR REPLACE FUNCTION logs.audit_trigger()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
DECLARE
USER_ID VARCHAR;
ENTITY_ID VARCHAR;
BEGIN
IF TG_OP = 'INSERT'
THEN
USER_ID := to_json(NEW)->'created_by';
ENTITY_ID := to_json(NEW)->'id';
INSERT INTO logs.audit_logs (
operation_name,
table_name,
log_type,
entity_id,
user_id,
after
)
VALUES (
TG_OP,
TG_TABLE_NAME,
TG_ARGV[0],
ENTITY_ID,
USER_ID,
to_jsonb(NEW)
);
RETURN NEW;
ELSIF TG_OP = 'UPDATE'
THEN
USER_ID := to_json(NEW)->'modified_by';
ENTITY_ID := to_json(NEW)->'id';
-- IF NEW != OLD THEN
INSERT INTO logs.audit_logs (
operation_name,
table_name,
log_type,
entity_id,
user_id,
before,
after
)
VALUES (
TG_OP,
TG_TABLE_NAME,
TG_ARGV[0],
ENTITY_ID,
USER_ID,
to_jsonb(OLD),
to_jsonb(NEW)
);
-- END IF;
RETURN NEW;
ELSIF TG_OP = 'DELETE'
THEN
USER_ID := to_json(OLD)->'modified_by';
ENTITY_ID := to_json(OLD)->'id';
INSERT INTO logs.audit_logs (
operation_name,
table_name,
log_type,
entity_id,
user_id,
before)
VALUES (
TG_OP,
TG_TABLE_NAME,
TG_ARGV[0],
ENTITY_ID,
USER_ID,
to_jsonb(OLD)
);
RETURN OLD;
END IF;
END;
$function$
;]]></string>
<result_param name="returnValue" jt="1111" type="trigger" />
</procedure>
</schema>
<connector name="PostgreSQL" database="PostgreSQL" driver_class="org.postgresql.Driver" driver_jar="postgresql-42.5.3.jar" driver_desc="Standard" host="localhost" port="5432" instance="lbstarter" user="postgres" passwd="cG9zdGdyZXN0ZXN0" useSystemProxy="false" />
<layout name="Parsed Script Layout" id="Layout_1041beb" show_relation="no_text" >
<entity schema="logs" name="audit_logs" color="3986C1" x="880" y="80" />
<entity schema="lbstarter" name="auth_clients" color="C1D8EE" x="880" y="400" />
<entity schema="lbstarter" name="roles" color="BED3F4" x="112" y="96" />
<entity schema="lbstarter" name="tenants" color="BED3F4" x="288" y="320" />
<entity schema="lbstarter" name="user_credentials" color="3986C1" x="656" y="80" />
<entity schema="lbstarter" name="user_tenant_permissions" color="BED3F4" x="48" y="320" />
<entity schema="lbstarter" name="user_tenants" color="3986C1" x="288" y="80" />
<entity schema="lbstarter" name="users" color="BED3F4" x="464" y="80" />
<group name="audit" color="C4E0F9" >
<entity schema="logs" name="audit_logs" />
</group>
<group name="Auth" color="C4E0F9" >
<entity schema="lbstarter" name="auth_clients" />
</group>
<group name="user_tenants" color="ECF0F7" >
<entity schema="lbstarter" name="roles" />
<entity schema="lbstarter" name="tenants" />
<entity schema="lbstarter" name="user_tenant_permissions" />
<entity schema="lbstarter" name="user_tenants" />
<entity schema="lbstarter" name="users" />
<entity schema="lbstarter" name="user_credentials" />
</group>
<script name="SQL_Editor" id="Editor_1274822" language="SQL" >
<string><![CDATA[
ALTER TABLE lbstarter.roles ADD CONSTRAINT fk_created_by FOREIGN KEY ( created_by ) REFERENCES lbstarter.user_tenants( id );
ALTER TABLE lbstarter.roles ADD CONSTRAINT fk_modified_by FOREIGN KEY ( modified_by ) REFERENCES lbstarter.user_tenants( id );
ALTER TABLE lbstarter.tenants ADD CONSTRAINT fk_created_by FOREIGN KEY ( created_by ) REFERENCES lbstarter.user_tenants( id );
ALTER TABLE lbstarter.tenants ADD CONSTRAINT fk_modified_by FOREIGN KEY ( modified_by ) REFERENCES lbstarter.user_tenants( id );
ALTER TABLE lbstarter.users ADD CONSTRAINT fk_user_user_tenant_created_by FOREIGN KEY ( created_by ) REFERENCES lbstarter.user_tenants( id );
ALTER TABLE lbstarter.users ADD CONSTRAINT fk_user_user_tenant_modified_by FOREIGN KEY ( modified_by ) REFERENCES lbstarter.user_tenants( id );
]]></string>
</script>
</layout>
</project>