-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path50_create_languages_translations.sql
757 lines (702 loc) · 28.7 KB
/
50_create_languages_translations.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
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/*
GROUP HEADERS GENERATED BY: https://patorjk.com/software/taag/#p=display&h=0&v=1&c=c&f=ANSI%20Shadow&t=STAGE%20FUNCS
SUB GROUP HEADERS GENERATED BY: https://patorjk.com/software/taag/#p=display&h=1&v=1&c=c&f=Banner3&t=permissions
*/
select *
from start_version_update('1', 'Initial version', _component := 'languages_translations');
/***
* ████████╗ █████╗ ██████╗ ██╗ ███████╗███████╗
* ╚══██╔══╝██╔══██╗██╔══██╗██║ ██╔════╝██╔════╝
* ██║ ███████║██████╔╝██║ █████╗ ███████╗
* ██║ ██╔══██║██╔══██╗██║ ██╔══╝ ╚════██║
* ██║ ██║ ██║██████╔╝███████╗███████╗███████║
* ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝╚══════╝╚══════╝
*
*/
create table const.language
(
code text not null primary key,
value text not null,
tenant_id integer default 1 not null references auth.tenant (tenant_id),
is_frontend_language boolean default true not null,
is_backend_language boolean default false not null,
is_communication_language boolean default true not null,
frontend_logical_order integer,
backend_logical_order integer,
communication_logical_order integer,
is_default_frontend_language boolean default false not null,
is_default_backend_language boolean default false not null,
is_default_communication_language boolean default false not null,
custom_data jsonb
)
inherits (public._template_timestamps);
create table translation
(
translation_id int generated always as identity not null primary key,
language_code text not null references const.language (code) on delete cascade,
tenant_id int not null references auth.tenant (tenant_id) default 1,
data_group text,
data_object_code text,
data_object_id bigint,
value text not null,
ua_search_data text not null,
ts_search_data tsvector not null
) inherits (_template_timestamps);
create unique index uq_translation_code on translation (language_code, data_group, data_object_code);
create unique index uq_translation_obj_id on translation (language_code, data_group, data_object_id);
create or replace function helpers.calculate_ts_regconfig(_language_code text)
returns regconfig
immutable
parallel safe
language plpgsql
as
$$
begin
_language_code := trim(lower(_language_code));
if _language_code = 'en' then
return 'english';
elseif _language_code = 'de' then
return 'german';
else
return 'english';
end if;
end;
$$;
create or replace function helpers.calculate_translation_fields() returns trigger as
$$
begin
if tg_op = 'INSERT' or tg_op = 'UPDATE' then
new.ua_search_data = helpers.unaccent_text(new.value);
new.ts_search_data = to_tsvector(helpers.calculate_ts_regconfig(new.language_code), new.value);
return new;
end if;
end;
$$ language plpgsql;
create trigger trg_translation
before insert or update
on public.translation
for each row
execute procedure helpers.calculate_translation_fields();
/***
* ██╗ █████╗ ███╗ ██╗ ██████╗ ███████╗██╗ ██╗███╗ ██╗ ██████╗███████╗
* ██║ ██╔══██╗████╗ ██║██╔════╝ ██╔════╝██║ ██║████╗ ██║██╔════╝██╔════╝
* ██║ ███████║██╔██╗ ██║██║ ███╗ █████╗ ██║ ██║██╔██╗ ██║██║ ███████╗
* ██║ ██╔══██║██║╚██╗██║██║ ██║ ██╔══╝ ██║ ██║██║╚██╗██║██║ ╚════██║
* ███████╗██║ ██║██║ ╚████║╚██████╔╝ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████║
* ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝
*
*/
create function const.create_language(_created_by text
, _user_id bigint
, _language_code text
, _title_in_natural_form text
, _is_frontend_language bool default true
, _is_backend_language bool default false
, _is_communication_language bool default true
, _frontend_logical_order int default null
, _backend_logical_order int default null
, _communication_logical_order int default null
, _is_default_frontend_language bool default false
, _is_default_backend_language bool default false
, _is_default_communication_language bool default false
, _custom_data jsonb default null
, _tenant_id int default 1)
returns table
(
__code text
)
language plpgsql
as
$$
begin
perform auth.has_permission(_user_id, 'languages.create_language', _tenant_id);
return query
insert into const.language (created_by, modified_by, code, value, tenant_id,
is_frontend_language, is_backend_language, is_communication_language,
is_default_frontend_language, is_default_backend_language,
is_default_communication_language,
frontend_logical_order,
backend_logical_order,
communication_logical_order,
custom_data)
values ( _created_by, _created_by, _language_code, _title_in_natural_form, _tenant_id
, _is_frontend_language, _is_backend_language, _is_communication_language
, _is_default_frontend_language, _is_default_backend_language, _is_default_communication_language
, _frontend_logical_order
, _backend_logical_order
, _communication_logical_order
, _custom_data)
returning code;
if (_is_default_frontend_language) then
update const.language
set is_default_frontend_language = false
where code <> _language_code;
end if;
if (_is_default_backend_language) then
update const.language
set is_default_backend_language = false
where code <> _language_code;
end if;
if (_is_default_communication_language) then
update const.language
set is_default_communication_language = false
where code <> _language_code;
end if;
perform add_journal_msg(_created_by
, _user_id
, format('Language (code: %s) created by user: %s'
, _language_code, _created_by)
, 'language'
, _data_object_code := _language_code
, _payload := array [
'value', _title_in_natural_form,
'is_frontend_language', _is_frontend_language::text,
'is_backend_language', _is_backend_language::text,
'is_communication_language', _is_communication_language::text,
'is_default_frontend_language', _is_default_frontend_language::text,
'is_default_backend_language', _is_default_backend_language::text,
'is_default_communication_language', _is_default_communication_language::text,
'frontend_logical_order', _frontend_logical_order::text,
'backend_logical_order', _backend_logical_order::text,
'communication_logical_order', _communication_logical_order::text,
'custom_data', _custom_data::text
]
, _event_id := 60011
, _tenant_id := _tenant_id);
end;
$$;
create function const.update_language(_modified_by text
, _user_id bigint
, _language_code text
, _title_in_natural_form text
, _is_frontend_language bool
, _is_backend_language bool
, _is_communication_language bool default true
, _frontend_logical_order int default null
, _backend_logical_order int default null
, _communication_logical_order int default null
, _is_default_frontend_language bool default false
, _is_default_backend_language bool default false
, _is_default_communication_language bool default false
, _custom_data jsonb default null
, _tenant_id int default 1)
returns table
(
__code text
)
language plpgsql
as
$$
begin
perform auth.has_permission(_user_id, 'languages.update_language', _tenant_id);
return query
update const.language
set modified = now(),
modified_by = _modified_by,
value = _title_in_natural_form,
is_frontend_language = _is_frontend_language,
is_backend_language = _is_backend_language,
is_communication_language = _is_communication_language,
is_default_frontend_language = _is_default_frontend_language,
is_default_backend_language = _is_default_backend_language,
is_default_communication_language = _is_default_communication_language,
frontend_logical_order = _frontend_logical_order,
backend_logical_order = _backend_logical_order,
communication_logical_order = _communication_logical_order,
custom_data = _custom_data
where code = _language_code and tenant_id = _tenant_id
returning code;
perform add_journal_msg(_modified_by
, _user_id
, format('Language (code: %s) updated by user: %s'
, _language_code, _modified_by)
, 'language'
, _data_object_code := _language_code
, _payload := array [
'value', _title_in_natural_form,
'is_frontend_language', _is_frontend_language::text,
'is_backend_language', _is_backend_language::text,
'is_communication_language', _is_communication_language::text,
'is_default_frontend_language', _is_default_frontend_language::text,
'is_default_backend_language', _is_default_backend_language::text,
'is_default_communication_language', _is_default_communication_language::text,
'frontend_logical_order', _frontend_logical_order::text,
'backend_logical_order', _backend_logical_order::text,
'communication_logical_order', _communication_logical_order::text,
'custom_data', _custom_data::text
]
, _event_id := 60012
, _tenant_id := _tenant_id);
end;
$$;
create function const.delete_language(_deleted_by text
, _user_id bigint
, _language_code text
, _tenant_id int default 1)
returns table
(
__code text
)
language plpgsql
as
$$
begin
perform auth.has_permission(_user_id, 'languages.delete_language', _tenant_id);
return query
delete from const.language
where code = _language_code and tenant_id = _tenant_id
returning code;
perform add_journal_msg(_deleted_by
, _user_id
, format('Language (code: %s) deleted by user: %s'
, _language_code, _deleted_by)
, 'language'
, _data_object_code := _language_code
, _event_id := 60013
, _tenant_id := _tenant_id);
end
$$;
create function const.get_language(_language_code text)
returns setof const.language
language sql
as
$$
select *
from const.language
where code = _language_code;
$$;
create function const.get_languages(_display_language_code text,
_is_frontend_language bool default null,
_is_backend_language bool default null,
_is_communication_language bool default null)
returns table
(
__code text,
__value text,
__is_frontend_language bool,
__is_backend_language bool,
__is_communication_language bool,
__is_default_frontend_language bool,
__is_default_backend_language bool,
__is_default_communication_language bool,
__frontend_logical_order int,
__backend_logical_order int,
__communication_logical_order int
)
language sql
as
$$
select l.code
, coalesce(t.value, l.value)
, l.is_frontend_language
, l.is_backend_language
, l.is_communication_language
, l.is_default_frontend_language
, l.is_default_backend_language
, l.is_default_communication_language
, l.frontend_logical_order
, l.backend_logical_order
, l.communication_logical_order
from const.language l
left join translation t
on t.language_code = _display_language_code and data_group = 'language' and data_object_code = l.code
where (_is_frontend_language is null or is_frontend_language = _is_frontend_language)
and (_is_backend_language is null or is_backend_language = _is_backend_language)
and (_is_communication_language is null or is_communication_language = _is_communication_language)
order by l.code;
$$;
create function const.get_frontend_languages(_display_language_code text)
returns table
(
__code text,
__value text,
__custom_data jsonb
)
language sql
as
$$
select l.code
, coalesce(t.value, l.value)
, l.custom_data
from const.language l
left join translation t
on t.language_code = _display_language_code and data_group = 'language' and data_object_code = l.code
where is_frontend_language = true
order by l.frontend_logical_order, coalesce(t.value, l.value);
$$;
create function const.get_backend_languages(_display_language_code text)
returns table
(
__code text,
__value text,
__custom_data jsonb
)
language sql
as
$$
select l.code
, coalesce(t.value, l.value)
, l.custom_data
from const.language l
left join translation t
on t.language_code = _display_language_code and data_group = 'language' and data_object_code = l.code
where is_backend_language = true
order by l.backend_logical_order, coalesce(t.value, l.value);
$$;
create function const.get_communication_languages(_display_language_code text)
returns table
(
__code text,
__value text,
__custom_data jsonb
)
language sql
as
$$
select l.code
, coalesce(t.value, l.value)
, l.custom_data
from const.language l
left join translation t
on t.language_code = _display_language_code and data_group = 'language' and data_object_code = l.code
where is_communication_language = true
order by l.communication_logical_order, coalesce(t.value, l.value);
$$;
create function const.get_default_language(
_display_language_code text,
_is_frontend_language bool default null,
_is_backend_language bool default null,
_is_communication_language bool default null)
returns table
(
__code text,
__value text,
__is_frontend_language bool,
__is_backend_language bool,
__is_communication_language bool,
__is_default_frontend_language bool,
__is_default_backend_language bool,
__is_default_communication_language bool,
__frontend_logical_order int,
__backend_logical_order int,
__communication_logical_order int,
__custom_data jsonb
)
language sql
as
$$
select l.code
, coalesce(t.value, l.value)
, l.is_frontend_language
, l.is_backend_language
, l.is_communication_language
, l.is_default_frontend_language
, l.is_default_backend_language
, l.is_default_communication_language
, l.frontend_logical_order
, l.backend_logical_order
, l.communication_logical_order
, l.custom_data
from const.language l
left join translation t
on t.language_code = _display_language_code and data_group = 'language' and data_object_code = l.code
where (_is_frontend_language is null or
(l.is_frontend_language = _is_frontend_language and is_default_frontend_language))
and (_is_backend_language is null or (l.is_backend_language = _is_backend_language and is_default_backend_language))
and (_is_communication_language is null or
(l.is_communication_language = _is_communication_language and is_default_communication_language))
order by l.code;
$$;
/***
* ████████╗██████╗ █████╗ ███╗ ██╗███████╗ ███████╗██╗ ██╗███╗ ██╗ ██████╗███████╗
* ╚══██╔══╝██╔══██╗██╔══██╗████╗ ██║██╔════╝ ██╔════╝██║ ██║████╗ ██║██╔════╝██╔════╝
* ██║ ██████╔╝███████║██╔██╗ ██║███████╗ █████╗ ██║ ██║██╔██╗ ██║██║ ███████╗
* ██║ ██╔══██╗██╔══██║██║╚██╗██║╚════██║ ██╔══╝ ██║ ██║██║╚██╗██║██║ ╚════██║
* ██║ ██║ ██║██║ ██║██║ ╚████║███████║ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████║
* ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝
*
*/
create or replace function public.create_translation(_created_by text, _user_id integer, _language_code text,
_data_group text, _data_object_code text default null::text,
_data_object_id bigint default null::bigint,
_value text default null::text,
_tenant_id integer default 1) returns table (
__translation_id integer,
__tenant_id integer,
__tenant_title text,
__language_code text,
__data_group text,
__data_object_code text,
__data_object_id bigint,
__value text
)
language plpgsql
as
$$
declare
__last_id int;
begin
perform auth.has_permission(_user_id, 'translations.create_translation', _tenant_id);
insert into translation (created_by, tenant_id, language_code, data_group, data_object_code, data_object_id, value)
values (_created_by, _tenant_id, _language_code, _data_group, _data_object_code, _data_object_id, _value)
returning translation_id
into __last_id;
perform add_journal_msg(_created_by
, _user_id
, format('Translation (data group: %s, data id/code: %s) created by user: %s'
, _data_group, coalesce(_data_object_id::text, _data_object_code), _created_by)
, 'translation'
, _data_object_id := __last_id
, _data_object_code := _data_object_code
, _event_id := 60021
, _tenant_id := _tenant_id);
return query
select t.translation_id
, t.tenant_id
, te.title
, t.language_code
, t.data_group
, t.data_object_code
, t.data_object_id
, t.value
from translation t
inner join auth.tenant te on t.tenant_id = te.tenant_id
where t.translation_id = __last_id;
end;
$$;
-- drop function public.update_translation(_modified_by text, _user_id int, _translation_id integer,
-- _value text, _tenant_id int);
create or replace function public.update_translation(_modified_by text, _user_id bigint, _translation_id integer,
_value text, _tenant_id integer default 1)
returns TABLE
(
__translation_id integer,
__tenant_id integer,
__language_code text,
__data_group text,
__data_object_code text,
__data_object_id bigint,
__value text
)
language plpgsql
as
$$
begin
perform auth.has_permission(_user_id, 'translations.update_translation', _tenant_id);
return query
update translation set
modified = now(),
modified_by = _modified_by,
value = _value
where translation_id = _translation_id and tenant_id = _tenant_id
returning translation_id
, tenant_id
, language_code
, data_group
, data_object_code
, data_object_id
, value;
perform add_journal_msg(_modified_by
, _user_id
, format('Translation updated by user: %s'
, _modified_by)
, 'translation'
, _data_object_id := _translation_id
, _event_id := 60022
, _tenant_id := _tenant_id);
end;
$$;
create or replace function public.delete_translation(_deleted_by text, _user_id integer, _translation_id integer,
_tenant_id integer default 1) returns SETOF translation
language plpgsql
as
$$
begin
perform auth.has_permission(_user_id, 'translations.delete_translation', _tenant_id);
return query
delete from translation
where translation_id = _translation_id and tenant_id = _tenant_id
returning *;
perform add_journal_msg(_deleted_by
, _user_id
, format('Translation deleted by user: %s'
, _deleted_by)
, 'translation'
, _data_object_id := _translation_id
, _event_id := 60023
, _tenant_id := _tenant_id);
end;
$$;
create or replace function public.copy_translations(_created_by text, _user_id bigint, _from_language_code text,
_to_language_code text, _from_tenant_id integer default 1,
_to_tenant_id integer default 1, _overwrite boolean default false,
_data_group text default null::text)
returns TABLE
(
__operation text,
__rows_count bigint
)
language plpgsql
as
$$
begin
perform auth.has_permission(_user_id, 'translations.create_translation', _to_tenant_id);
return query
with updated_rows as materialized (
update translation
set modified = now(),
modified_by = _created_by,
value = source.value
from (select data_group, data_object_code, data_object_id, value
from translation st
where st.tenant_id = _from_tenant_id
and st.language_code = _from_language_code
and (helpers.is_empty_string(_data_group) or data_group = _data_group)) as source
where
_overwrite
and translation.tenant_id = _to_tenant_id
and translation.language_code = _to_language_code
and translation.data_group = source.data_group
and coalesce(translation.data_object_code, '') = coalesce(source.data_object_code, '')
and coalesce(translation.data_object_id, 0) = coalesce(source.data_object_id, 0)
returning translation_id)
, new_rows as materialized (
insert
into translation (created_by, modified_by, tenant_id, language_code, data_group, data_object_code,
data_object_id, value)
select _created_by
, _created_by
, _to_tenant_id
, _to_language_code
, t.data_group
, t.data_object_code
, t.data_object_id
, t.value
from translation t
left join translation dt on dt.tenant_id = _to_tenant_id and
dt.language_code = _to_language_code and
coalesce(t.data_object_code, '') = coalesce(dt.data_object_code, '') and
coalesce(t.data_object_id, 0) = coalesce(dt.data_object_id, 0)
where t.tenant_id = _from_tenant_id
and t.language_code = _from_language_code
and (helpers.is_empty_string(_data_group) or t.data_group = _data_group)
and dt is null
returning translation_id)
select 'updated', count(*)
from updated_rows
union all
select 'created', count(*)
from new_rows
order by 1;
end;
$$;
-- drop function search_translations(_page int, _page_size int,
-- _tenant_id int,
-- _language_code text,
-- _data_group text,
-- _data_object_code text,
-- _data_object_id bigint,
-- _value_search_text text
-- );
create or replace function public.search_translations(_display_language_code text, _page integer default 1,
_page_size integer default 10,
_tenant_id integer default null::integer,
_language_code text default null::text,
_data_group text default null::text,
_data_object_code text default null::text,
_data_object_id bigint default null::bigint,
_value_search_text text default null::text)
returns TABLE
(
__translation_id integer,
__tenant_id integer,
__tenant_title text,
__language_code text,
__language_value text,
__data_group text,
__data_object_code text,
__data_object_id bigint,
__value text,
__total_items bigint
)
language plpgsql
as
$$
declare
begin
return query
with filtered_rows
as (select t.translation_id
, count(*) over () as total_items
from translation t
where (_tenant_id is null
or tenant_id = _tenant_id)
and (helpers.is_empty_string(_language_code)
or language_code = _language_code)
and (helpers.is_empty_string(_data_group)
or lower(data_group) = lower(_data_group))
and (helpers.is_empty_string(_data_object_code)
or lower(data_object_code) = lower(_data_object_code))
and (_data_object_id is null
or data_object_id = _data_object_id)
and (helpers.is_empty_string(_value_search_text)
or
helpers.unaccent_text(value) like '%' || helpers.unaccent_text(_value_search_text) || '%')
order by data_group, data_object_code, data_object_id nulls last, language_code
offset ((_page - 1) * _page_size) limit _page_size)
select t.translation_id
, t.tenant_id
, te.title
, t.language_code
, tl.value
, t.data_group
, t.data_object_code
, t.data_object_id
, t.value
, total_items
from filtered_rows fr
inner join translation t on fr.translation_id = t.translation_id
inner join auth.tenant te on t.tenant_id = te.tenant_id
left join translation tl on tl.language_code = _display_language_code and tl.data_group = 'language' and
tl.data_object_code = t.language_code
order by data_group, data_object_code, data_object_id nulls last, language_code;
end;
$$;
/***
* ██████ ██████ ███████ ████████ ██████ ██████ ███████ █████ ████████ ███████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██████ ██ ██ ███████ ██ █████ ██ ██████ █████ ███████ ██ █████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ██████ ███████ ██ ██████ ██ ██ ███████ ██ ██ ██ ███████
*
*
*/
create or replace procedure internal.load_initial_languages_data()
language plpgsql
as
$$
declare
__null bigint;
begin
perform unsecure.create_permission_as_system('Languages', _is_assignable := false);
perform unsecure.create_permission_as_system('Create language', 'languages');
perform unsecure.create_permission_as_system('Update language', 'languages');
perform unsecure.create_permission_as_system('Delete language', 'languages');
perform unsecure.create_permission_as_system('Translations', _is_assignable := false);
perform unsecure.create_permission_as_system('Create translation', 'translations');
perform unsecure.create_permission_as_system('Read translation', 'translations');
perform unsecure.create_permission_as_system('Update translation', 'translations');
perform unsecure.create_permission_as_system('Delete translation', 'translations');
select ps.perm_set_id
from auth.perm_set ps
, lateral auth.add_perm_set_permissions('update_script_v2.1', 1,
ps.perm_set_id, array ['languages', 'translations'], 1)
where code in ('system_admin',
'tenant_creator',
'tenant_admin')
into __null;
end
$$;
call internal.load_initial_languages_data();
select *
from stop_version_update('1', _component := 'languages_translations');