-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
606 lines (499 loc) · 24.5 KB
/
schema.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
--
-- DATA TABLES
--
CREATE TABLE public."Users" (
id text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
role text DEFAULT 'USER' NOT NULL,
image text,
first_name text,
last_name text,
username text,
email text,
is_breaker boolean DEFAULT false NOT NULL,
paysafe_user_id text,
bc_user_id integer
);
CREATE TABLE public."BreakerProfiles" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
bio text NOT NULL,
video text NOT NULL,
instagram text,
twitter text,
facebook text,
linkedin text,
tiktok text
);
CREATE TABLE public."Streams" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
stream_id text NOT NULL,
stream_key text NOT NULL,
playback_id text NOT NULL,
stream_url text NOT NULL
);
CREATE TABLE public."UserPreferences" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
frequency text NOT NULL,
sports text[] NOT NULL,
pricing text[] NOT NULL,
break_type text[] NOT NULL
);
CREATE TABLE public."Notifications" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
before_15_min boolean DEFAULT false NOT NULL,
when_live boolean DEFAULT false NOT NULL
);
CREATE TABLE public."Addresses" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
first_name text NOT NULL,
last_name text NOT NULL,
line1 text NOT NULL,
line2 text,
city text NOT NULL,
country text NOT NULL,
state_province_region text NOT NULL,
postal_zip_code text NOT NULL,
is_default boolean DEFAULT false
);
CREATE TABLE public."Events" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
title text NOT NULL,
description text NOT NULL,
status text DEFAULT 'DRAFT' NOT NULL,
start_time timestamp with time zone,
image text NOT NULL,
archived boolean NOT NULL DEFAULT false
);
CREATE TABLE public."Breaks" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
title text NOT NULL,
description text NOT NULL,
status text DEFAULT 'DRAFT' NOT NULL,
event_id uuid NOT NULL,
image text NOT NULL,
break_type text NOT NULL,
spots integer NOT NULL,
teams_per_spot integer,
price numeric,
result jsonb,
datset jsonb,
archived boolean NOT NULL DEFAULT false
);
CREATE TABLE public."Products" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
unit_of_measure text NOT NULL,
description text,
year text NOT NULL,
manufacturer text NOT NULL,
brand text NOT NULL,
series text,
category text NOT NULL,
type text,
boxes_per_case integer,
packs_per_box integer,
cards_per_pack integer,
card_number text,
player text,
parallel text,
insert text,
rookie_card boolean DEFAULT false,
memoribillia text,
autograph boolean DEFAULT false,
numbered integer,
grader text,
grade text,
available boolean DEFAULT true NOT NULL
);
CREATE TABLE public."Inventory" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
product_id uuid NOT NULL,
supplier text NOT NULL,
location text NOT NULL,
purchase_date timestamp with time zone DEFAULT now() NOT NULL,
cost_basis numeric NOT NULL,
break_id uuid
);
CREATE TABLE public."BreakProductItems" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
title text NOT NULL,
quantity integer NOT NULL,
break_id uuid NOT NULL,
order_id uuid,
price numeric NOT NULL,
bc_product_id integer NOT NULL,
bc_variant_id integer,
CONSTRAINT "BreakProductItems_quantity_positive" CHECK (quantity >= 0)
);
CREATE TABLE public."ExtensibleValues" (
value text NOT NULL,
field text NOT NULL
);
CREATE TABLE public."Orders" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
bc_order_id integer NOT NULL,
subtotal numeric NOT NULL,
discount_total numeric NOT NULL,
tax_total numeric NOT NULL,
shipping_total numeric NOT NULL,
grand_total numeric NOT NULL
);
CREATE TABLE public."SaveBreak" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
break_id uuid NOT NULL
);
CREATE TABLE public."SaveEvent" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
event_id uuid NOT NULL
);
CREATE TABLE public."SaveBreaker" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
breaker_id text NOT NULL
);
CREATE TABLE public."Hits" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
description text,
user_id text NOT NULL,
break_id uuid NOT NULL,
image_front text NOT NULL,
image_back text,
year text NOT NULL,
manufacturer text NOT NULL,
brand text NOT NULL,
series text,
category text NOT NULL,
card_number text NOT NULL,
player text NOT NULL,
parallel text,
insert text,
rookie_card boolean DEFAULT false,
memoribillia text,
autograph boolean DEFAULT false,
numbered integer,
archived boolean NOT NULL DEFAULT false
);
CREATE TABLE public."NotificationSettings" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id text NOT NULL,
events BOOLEAN NOT NULL DEFAULT false,
breaks BOOLEAN NOT NULL DEFAULT false,
breakers BOOLEAN NOT NULL DEFAULT false
);
CREATE TABLE public."Teams" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
name text NOT NULL,
year_start integer NOT NULL,
year_end integer NOT NULL,
color text NOT NULL,
color_secondary text NOT NULL,
sport text NOT NULL
);
CREATE TABLE public."Players" (
id uuid DEFAULT gen_random_uuid() NOT NULL,
name text NOT NULL,
sport text NOT NULL
);
--
-- ENUM TABLES
--
CREATE TABLE public.unit_of_measure (
value text NOT NULL
);
CREATE TABLE public.user_role (
value text NOT NULL
);
CREATE TABLE public.event_status (
value text NOT NULL
);
CREATE TABLE public.break_status (
value text NOT NULL
);
CREATE TABLE public.break_type (
value text NOT NULL
);
--
-- ENUM VALUES
--
INSERT INTO public.unit_of_measure (value) VALUES
('CASE'),
('BOX'),
('PACK'),
('CARD');
INSERT INTO public.user_role (value) VALUES
('USER'),
('MANAGER'),
('ADMIN');
INSERT INTO public.event_status (value) VALUES
('DRAFT'),
('SCHEDULED'),
('LIVE'),
('COMPLETED');
INSERT INTO public.break_status (value) VALUES
('DRAFT'),
('AVAILABLE'),
('SOLDOUT'),
('LIVE'),
('COMPLETED');
INSERT INTO public.break_type (value) VALUES
('RANDOM_TEAM'),
('RANDOM_DIVISION'),
('PICK_YOUR_TEAM'),
('PICK_YOUR_DIVISION'),
('HIT_DRAFT'),
('PERSONAL');
--
-- PRIMARY KEYS
--
ALTER TABLE ONLY public."Users" ADD CONSTRAINT "Users_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."BreakerProfiles" ADD CONSTRAINT "BreakerProfiles_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Streams" ADD CONSTRAINT "Streams_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."UserPreferences" ADD CONSTRAINT "UserPreferences_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Notifications" ADD CONSTRAINT "Notifications_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Addresses" ADD CONSTRAINT "Addresses_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Events" ADD CONSTRAINT "Events_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Breaks" ADD CONSTRAINT "Breaks_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Products" ADD CONSTRAINT "Products_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Inventory" ADD CONSTRAINT "Inventory_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."BreakProductItems" ADD CONSTRAINT "BreakProductItems_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."ExtensibleValues" ADD CONSTRAINT "ExtensibleValues_pkey" PRIMARY KEY (value, field);
ALTER TABLE ONLY public."Orders" ADD CONSTRAINT "Orders_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."SaveBreak" ADD CONSTRAINT "SaveBreak_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."SaveEvent" ADD CONSTRAINT "SaveEvent_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."SaveBreaker" ADD CONSTRAINT "SaveBreaker_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Hits" ADD CONSTRAINT "Hits_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."NotificationSettings" ADD CONSTRAINT "NotificationSettings_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Teams" ADD CONSTRAINT "Teams_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public."Players" ADD CONSTRAINT "Players_pkey" PRIMARY KEY (id);
ALTER TABLE ONLY public.unit_of_measure ADD CONSTRAINT unit_of_measure_pkey PRIMARY KEY (value);
ALTER TABLE ONLY public.user_role ADD CONSTRAINT user_role_pkey PRIMARY KEY (value);
ALTER TABLE ONLY public.event_status ADD CONSTRAINT event_status_pkey PRIMARY KEY (value);
ALTER TABLE ONLY public.break_status ADD CONSTRAINT break_status_pkey PRIMARY KEY (value);
ALTER TABLE ONLY public.break_type ADD CONSTRAINT break_type_pkey PRIMARY KEY (value);
--
-- FOREIGN KEYS
--
ALTER TABLE ONLY public."Users"
ADD CONSTRAINT "Users_role_fkey" FOREIGN KEY (role) REFERENCES public.user_role(value) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Users"
ADD CONSTRAINT "Users_username_key" UNIQUE (username);
ALTER TABLE ONLY public."BreakerProfiles"
ADD CONSTRAINT "BreakerProfiles_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."BreakerProfiles"
ADD CONSTRAINT "BreakerProfiles_user_id_key" UNIQUE (user_id);
ALTER TABLE ONLY public."Streams"
ADD CONSTRAINT "Streams_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Streams"
ADD CONSTRAINT "Streams_user_id_key" UNIQUE (user_id);
ALTER TABLE ONLY public."UserPreferences"
ADD CONSTRAINT "UserPreferences_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."UserPreferences"
ADD CONSTRAINT "UserPreferences_user_id_key" UNIQUE (user_id);
ALTER TABLE ONLY public."Notifications"
ADD CONSTRAINT "Notifications_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Notifications"
ADD CONSTRAINT "Notifications_user_id_key" UNIQUE (user_id);
ALTER TABLE ONLY public."Addresses"
ADD CONSTRAINT "Addresses_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Events"
ADD CONSTRAINT "Events_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Events"
ADD CONSTRAINT "Events_status_fkey" FOREIGN KEY (status) REFERENCES public.event_status(value) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Breaks"
ADD CONSTRAINT "Breaks_event_id_fkey" FOREIGN KEY (event_id) REFERENCES public."Events"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Breaks"
ADD CONSTRAINT "Breaks_status_fkey" FOREIGN KEY (status) REFERENCES public.break_status(value) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Breaks"
ADD CONSTRAINT "Breaks_break_type_fkey" FOREIGN KEY (break_type) REFERENCES public.break_type(value) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Products"
ADD CONSTRAINT "Products_unit_of_measure_fkey" FOREIGN KEY (unit_of_measure) REFERENCES public.unit_of_measure(value) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Inventory"
ADD CONSTRAINT "Inventory_product_id_fkey" FOREIGN KEY (product_id) REFERENCES public."Products"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Inventory"
ADD CONSTRAINT "Inventory_break_id_fkey" FOREIGN KEY (break_id) REFERENCES public."Breaks"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."BreakProductItems"
ADD CONSTRAINT "BreakProductItems_break_id_fkey" FOREIGN KEY (break_id) REFERENCES public."Breaks"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."BreakProductItems"
ADD CONSTRAINT "BreakProductItems_order_id_fkey" FOREIGN KEY (order_id) REFERENCES public."Orders"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."Orders"
ADD CONSTRAINT "Orders_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public."SaveBreak"
ADD CONSTRAINT "SaveBreak_break_id_fkey" FOREIGN KEY (break_id) REFERENCES public."Breaks"(id);
ALTER TABLE ONLY public."SaveBreak"
ADD CONSTRAINT "SaveBreak_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id);
ALTER TABLE ONLY public."SaveEvent"
ADD CONSTRAINT "SaveEvent_event_id_fkey" FOREIGN KEY (event_id) REFERENCES public."Events"(id);
ALTER TABLE ONLY public."SaveEvent"
ADD CONSTRAINT "SaveEvent_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id);
ALTER TABLE ONLY public."SaveBreaker"
ADD CONSTRAINT "SaveBreaker_breaker_id_fkey" FOREIGN KEY (breaker_id) REFERENCES public."Users"(id);
ALTER TABLE ONLY public."SaveBreaker"
ADD CONSTRAINT "SaveBreaker_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id);
ALTER TABLE ONLY public."Hits"
ADD CONSTRAINT "Hits_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id);
ALTER TABLE ONLY public."Hits"
ADD CONSTRAINT "Hits_break_id_fkey" FOREIGN KEY (break_id) REFERENCES public."Breaks"(id);
ALTER TABLE ONLY public."Hits"
ADD CONSTRAINT "Hits_product_id_fkey" FOREIGN KEY (product_id) REFERENCES public."Products"(id);
ALTER TABLE ONLY public."NotificationSettings"
ADD CONSTRAINT "NotificationSettings_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."Users"(id);
ALTER TABLE ONLY public."NotificationSettings"
ADD CONSTRAINT "NotificationSettings_user_id_unique_key" UNIQUE (user_id);
--
-- FUNCTIONS
--
CREATE OR REPLACE FUNCTION public.set_current_timestamp_on_row_update()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$function$;
CREATE OR REPLACE FUNCTION public.set_product_description()
RETURNS trigger
LANGUAGE plpgsql
AS $sku_desc_func$
DECLARE
_new record;
BEGIN
_new := NEW;
if NEW.unit_of_measure = 'CARD' then
_new."description" := CONCAT(NEW.year,' ',NEW.manufacturer,' ',NEW.brand,' ', NEW.series,' ',NEW.card_number,' ',NEW.player,' ',NEW.parallel,' ',NEW.insert);
if NEW.autograph = TRUE then
_new."description" := CONCAT(_new."description",' ', 'Autograph');
END if;
if NEW.memoribillia IS NOT NULL and NEW.memoribillia != '' then
_new."description" := CONCAT(_new."description",' ', NEW.memoribillia);
END if;
if NEW.rookie_card = TRUE then
_new."description" := CONCAT(_new."description",' ', 'Rookie');
END if;
if NEW.numbered IS NOT NULL and NEW.numbered != 0 then
_new."description" := CONCAT(_new."description",' /', NEW.numbered);
END if;
if NEW.grader IS NOT NULL and NEW.grader != '' then
_new."description" := CONCAT(_new."description",' ', NEW.grader, ' ', NEW.grade);
END if;
if NEW.subcategory IS NOT NULL and NEW.subcategory != '' then
_new."description" := CONCAT(_new."description",' - ', NEW.subcategory);
END if;
else
_new."description" := CONCAT(NEW.year,' ',NEW.manufacturer,' ',NEW.brand,' ', NEW.series,' ',NEW.category,' ',NEW.type,' ',NEW.unit_of_measure);
if NEW.subcategory IS NOT NULL and NEW.subcategory != '' then
_new."description" := CONCAT(_new."description",' - ', NEW.subcategory);
END if;
END if;
RETURN _new;
END;
$sku_desc_func$;
CREATE OR REPLACE FUNCTION public.set_hit_description()
RETURNS trigger
LANGUAGE plpgsql
AS $sku_desc_func$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."description" := CONCAT(NEW.year,' ',NEW.manufacturer,' ',NEW.brand,' ', NEW.series,' ',NEW.card_number,' ',NEW.player,' ',NEW.parallel,' ',NEW.insert);
if NEW.autograph = TRUE then
_new."description" := CONCAT(_new."description",' ', 'Autograph');
END if;
if NEW.memoribillia IS NOT NULL and NEW.memoribillia != '' then
_new."description" := CONCAT(_new."description",' ', NEW.memoribillia);
END if;
if NEW.rookie_card = TRUE then
_new."description" := CONCAT(_new."description",' ', 'Rookie');
END if;
if NEW.numbered IS NOT NULL and NEW.numbered != 0 then
_new."description" := CONCAT(_new."description",' /', NEW.numbered);
END if;
RETURN _new;
END;
$sku_desc_func$;
--
-- TRIGGERS
--
CREATE TRIGGER "set_public_Users_updated_at" BEFORE UPDATE ON public."Users" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Users_updated_at" ON public."Users" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_BreakerProfiles_updated_at" BEFORE UPDATE ON public."BreakerProfiles" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_BreakerProfiles_updated_at" ON public."BreakerProfiles" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Streams_updated_at" BEFORE UPDATE ON public."Streams" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Streams_updated_at" ON public."Streams" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_UserPreferences_updated_at" BEFORE UPDATE ON public."UserPreferences" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_UserPreferences_updated_at" ON public."UserPreferences" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Notifications_updated_at" BEFORE UPDATE ON public."Notifications" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Notifications_updated_at" ON public."Notifications" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Addresses_updated_at" BEFORE UPDATE ON public."Addresses" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Addresses_updated_at" ON public."Addresses" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Events_updated_at" BEFORE UPDATE ON public."Events" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Events_updated_at" ON public."Events" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Breaks_updated_at" BEFORE UPDATE ON public."Breaks" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Breaks_updated_at" ON public."Breaks" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Inventory_updated_at" BEFORE UPDATE ON public."Inventory" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Inventory_updated_at" ON public."Inventory" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Products_updated_at" BEFORE UPDATE ON public."Products" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Products_updated_at" ON public."Products" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Products_description" BEFORE INSERT OR UPDATE ON public."Products" FOR EACH ROW EXECUTE FUNCTION public.set_product_description();
COMMENT ON TRIGGER "set_public_Products_description" ON public."Products" IS 'trigger to set description column on Products';
CREATE TRIGGER "set_public_BreakProductItems_updated_at" BEFORE UPDATE ON public."BreakProductItems" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_BreakProductItems_updated_at" ON public."BreakProductItems" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Orders_updated_at" BEFORE UPDATE ON public."Orders" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Orders_updated_at" ON public."Orders" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_SaveBreak_updated_at" BEFORE UPDATE ON public."SaveBreak" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_SaveBreak_updated_at" ON public."SaveBreak" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_SaveEvent_updated_at" BEFORE UPDATE ON public."SaveEvent" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_SaveEvent_updated_at" ON public."SaveEvent" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_SaveBreaker_updated_at" BEFORE UPDATE ON public."SaveBreaker" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_SaveBreaker_updated_at" ON public."SaveBreaker" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Hits_updated_at" BEFORE UPDATE ON public."Hits" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_Hits_updated_at" ON public."Hits" IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE TRIGGER "set_public_Hits_description" BEFORE INSERT OR UPDATE ON public."Hits" FOR EACH ROW EXECUTE FUNCTION public.set_hit_description();
COMMENT ON TRIGGER "set_public_Hits_description" ON public."Hits" IS 'trigger to set description column on Hits';
CREATE TRIGGER "set_public_NotificationSettings_updated_at" BEFORE UPDATE ON public."NotificationSettings" FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_on_row_update();
COMMENT ON TRIGGER "set_public_NotificationSettings_updated_at" ON public."NotificationSettings" IS 'trigger to set value of column "updated_at" to current timestamp on row update';