Repository navigation
Expand file tree
/
Copy pathschema.sql
More file actions
1736 lines (1612 loc) · 53.9 KB
/
Copy pathschema.sql
File metadata and controls
1736 lines (1612 loc) · 53.9 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
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- ============================================================
-- Generated PostgreSQL Schema from Base44 JSONC Entity Schemas
-- ============================================================
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-- ============================================================
-- Entity: AuditLog -> Table: audit_logs
-- ============================================================
CREATE TABLE IF NOT EXISTS audit_logs (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
user_id TEXT,
user_name TEXT,
action TEXT,
resource_type TEXT,
resource_id TEXT,
details TEXT,
ip_address TEXT,
user_agent TEXT,
severity TEXT,
metadata TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Base44Purchase -> Table: base44_purchases
-- ============================================================
CREATE TABLE IF NOT EXISTS base44_purchases (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
checkoutSessionId TEXT,
status TEXT,
user_id TEXT,
user_name TEXT,
plan_id TEXT,
plan_name TEXT,
expected_amount NUMERIC,
expected_currency TEXT,
entitlement TEXT,
is_trial BOOLEAN,
promo_code TEXT,
fulfilled BOOLEAN,
payment_id TEXT,
subscription_id TEXT,
paid_at TIMESTAMPTZ,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: BlogPost -> Table: blog_posts
-- ============================================================
CREATE TABLE IF NOT EXISTS blog_posts (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
title TEXT,
slug TEXT,
excerpt TEXT,
content TEXT,
category TEXT,
author_name TEXT,
author_id TEXT,
featured_image_url TEXT,
status TEXT,
published_date TIMESTAMPTZ,
tags TEXT,
read_time TEXT,
is_featured BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Booking -> Table: bookings
-- ============================================================
CREATE TABLE IF NOT EXISTS bookings (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
business_id TEXT,
business_name TEXT,
user_id TEXT,
user_name TEXT,
user_email TEXT,
user_phone TEXT,
booking_type TEXT,
booking_date TIMESTAMPTZ,
booking_time TEXT,
party_size NUMERIC,
notes TEXT,
status TEXT,
confirmed_at TIMESTAMPTZ,
cancelled_at TIMESTAMPTZ,
cancellation_reason TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Business -> Table: businesses
-- ============================================================
CREATE TABLE IF NOT EXISTS businesses (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
name TEXT,
legal_name TEXT,
description TEXT,
category TEXT,
subcategories TEXT,
year_founded NUMERIC,
business_category_id TEXT,
discount_percentage NUMERIC,
logo_url TEXT,
cover_image_url TEXT,
featured_image_url TEXT,
address TEXT,
city TEXT,
country TEXT,
postal_code TEXT,
latitude NUMERIC,
longitude NUMERIC,
service_area TEXT,
phone TEXT,
email TEXT,
website TEXT,
social_links TEXT,
primary_contact_name TEXT,
primary_contact_role TEXT,
primary_contact_phone TEXT,
primary_contact_email TEXT,
business_hours TEXT,
holiday_hours TEXT,
media_gallery TEXT,
verification_status TEXT,
vat_number TEXT,
vat_number_valid BOOLEAN,
company_registration_number TEXT,
registration_country TEXT,
kyc_submitted_at TIMESTAMPTZ,
verified_at TIMESTAMPTZ,
verifier_admin_id TEXT,
rejection_reason TEXT,
is_active BOOLEAN,
is_featured BOOLEAN,
average_rating NUMERIC,
total_reviews NUMERIC,
business_score NUMERIC,
tags TEXT,
tax_id TEXT,
parent_business_id TEXT,
seo_slug TEXT,
supported_languages TEXT,
amenities TEXT,
payment_methods TEXT,
visibility TEXT,
customer_messaging_enabled BOOLEAN,
booking_enabled BOOLEAN,
booking_url TEXT,
booking_config TEXT,
notification_prefs TEXT,
profile_completion NUMERIC,
profile_published BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: BusinessCategory -> Table: business_categories
-- ============================================================
CREATE TABLE IF NOT EXISTS business_categories (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
name TEXT,
description TEXT,
icon TEXT,
slug TEXT,
parent_id TEXT,
sort_order NUMERIC,
is_active BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: BusinessDocument -> Table: business_documents
-- ============================================================
CREATE TABLE IF NOT EXISTS business_documents (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
business_id TEXT,
business_name TEXT,
document_type TEXT,
file_url TEXT,
file_name TEXT,
status TEXT,
expiry_date TIMESTAMPTZ,
uploaded_by_id TEXT,
uploaded_by_name TEXT,
verified_by_id TEXT,
verified_date TIMESTAMPTZ,
rejection_reason TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: BusinessEmailBlast -> Table: business_email_blasts
-- ============================================================
CREATE TABLE IF NOT EXISTS business_email_blasts (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
business_id TEXT,
business_name TEXT,
business_category TEXT,
scope TEXT,
target_country TEXT,
target_city TEXT,
target_area TEXT,
subject TEXT,
body TEXT,
audience_count NUMERIC,
price NUMERIC,
currency TEXT,
status TEXT,
checkout_session_id TEXT,
payment_id TEXT,
review_notes TEXT,
reviewed_by_id TEXT,
reviewed_at TIMESTAMPTZ,
sent_count NUMERIC,
failed_count NUMERIC,
error_message TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: BusinessLocation -> Table: business_locations
-- ============================================================
CREATE TABLE IF NOT EXISTS business_locations (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
business_id TEXT,
business_name TEXT,
name TEXT,
address TEXT,
city TEXT,
country TEXT,
postal_code TEXT,
latitude NUMERIC,
longitude NUMERIC,
phone TEXT,
email TEXT,
business_hours TEXT,
is_primary BOOLEAN,
is_active BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Campaign -> Table: campaigns
-- ============================================================
CREATE TABLE IF NOT EXISTS campaigns (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
business_id TEXT,
business_name TEXT,
title TEXT,
description TEXT,
type TEXT,
status TEXT,
channels TEXT,
message_subject TEXT,
message_body TEXT,
start_date TIMESTAMPTZ,
end_date TIMESTAMPTZ,
scheduled_at TIMESTAMPTZ,
sent_at TIMESTAMPTZ,
target_audience TEXT,
target_city TEXT,
audience_filters TEXT,
total_recipients NUMERIC,
delivered_count NUMERIC,
opened_count NUMERIC,
clicked_count NUMERIC,
conversion_count NUMERIC,
coupon_id TEXT,
gift_campaign_id TEXT,
image_url TEXT,
opt_in_only BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: CampaignAudience -> Table: campaign_audiences
-- ============================================================
CREATE TABLE IF NOT EXISTS campaign_audiences (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
campaign_id TEXT,
campaign_title TEXT,
user_id TEXT,
user_name TEXT,
status TEXT,
sent_at TIMESTAMPTZ,
delivered_at TIMESTAMPTZ,
read_at TIMESTAMPTZ,
responded_at TIMESTAMPTZ,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: CampaignMessage -> Table: campaign_messages
-- ============================================================
CREATE TABLE IF NOT EXISTS campaign_messages (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
campaign_id TEXT,
campaign_title TEXT,
channel TEXT,
subject TEXT,
body TEXT,
scheduled_at TIMESTAMPTZ,
sent_at TIMESTAMPTZ,
status TEXT,
recipient_count NUMERIC,
open_count NUMERIC,
click_count NUMERIC,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: ChatMessage -> Table: chat_messages
-- ============================================================
CREATE TABLE IF NOT EXISTS chat_messages (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
conversation_id TEXT,
business_id TEXT,
business_name TEXT,
user_id TEXT,
user_name TEXT,
business_owner_id TEXT,
sender_type TEXT,
sender_id TEXT,
sender_name TEXT,
content TEXT,
is_read BOOLEAN,
read_at TIMESTAMPTZ,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: CommissionPayment -> Table: commission_payments
-- ============================================================
CREATE TABLE IF NOT EXISTS commission_payments (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
partner_id TEXT,
partner_name TEXT,
partner_email TEXT,
period TEXT,
gross_amount NUMERIC,
commission_rate NUMERIC,
net_amount NUMERIC,
currency TEXT,
status TEXT,
payment_method TEXT,
payment_date TIMESTAMPTZ,
transaction_reference TEXT,
referral_count NUMERIC,
breakdown TEXT,
notes TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: ComplianceRequest -> Table: compliance_requests
-- ============================================================
CREATE TABLE IF NOT EXISTS compliance_requests (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
user_id TEXT,
user_name TEXT,
user_email TEXT,
request_type TEXT,
status TEXT,
description TEXT,
consent_type TEXT,
consent_value BOOLEAN,
processed_by_id TEXT,
processed_by_name TEXT,
processed_at TIMESTAMPTZ,
export_url TEXT,
deletion_scheduled_at TIMESTAMPTZ,
retention_category TEXT,
retention_days NUMERIC,
resolution_notes TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: ConfigChangeLog -> Table: config_change_logs
-- ============================================================
CREATE TABLE IF NOT EXISTS config_change_logs (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
entity_type TEXT,
entity_id TEXT,
entity_key TEXT,
action TEXT,
previous_value TEXT,
new_value TEXT,
changed_by_id TEXT,
changed_by_name TEXT,
change_reason TEXT,
is_critical BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Coupon -> Table: coupons
-- ============================================================
CREATE TABLE IF NOT EXISTS coupons (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
business_id TEXT,
business_name TEXT,
code TEXT,
title TEXT,
description TEXT,
discount_percentage NUMERIC,
valid_from TIMESTAMPTZ,
valid_to TIMESTAMPTZ,
usage_limit NUMERIC,
used_count NUMERIC,
status TEXT,
premium_only BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: CrmRecord -> Table: crm_records
-- ============================================================
CREATE TABLE IF NOT EXISTS crm_records (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
business_id TEXT,
business_name TEXT,
user_id TEXT,
customer_name TEXT,
vip_flag BOOLEAN,
tags TEXT,
lifecycle_status TEXT,
marketing_consent BOOLEAN,
internal_notes TEXT,
follow_up_tasks TEXT,
custom_fields TEXT,
preferred_contact_method TEXT,
last_contacted_date TIMESTAMPTZ,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: DeveloperApp -> Table: developer_apps
-- ============================================================
CREATE TABLE IF NOT EXISTS developer_apps (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
name TEXT,
description TEXT,
app_type TEXT,
status TEXT,
scopes TEXT,
redirect_uri TEXT,
api_key TEXT,
api_secret_hash TEXT,
webhook_url TEXT,
webhook_secret TEXT,
webhook_events TEXT,
rate_limit_per_min NUMERIC,
ip_whitelist TEXT,
total_requests NUMERIC,
requests_today NUMERIC,
last_request_at TIMESTAMPTZ,
owner_name TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Device -> Table: devices
-- ============================================================
CREATE TABLE IF NOT EXISTS devices (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
user_id TEXT,
device_type TEXT,
device_id TEXT,
device_name TEXT,
os_version TEXT,
app_version TEXT,
push_token TEXT,
last_seen TIMESTAMPTZ,
ip_address TEXT,
is_active BOOLEAN,
is_trusted BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Discount -> Table: discounts
-- ============================================================
CREATE TABLE IF NOT EXISTS discounts (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
business_id TEXT,
business_name TEXT,
title TEXT,
description TEXT,
percentage NUMERIC,
category TEXT,
tags TEXT,
image_url TEXT,
min_purchase_amount NUMERIC,
max_discount_amount NUMERIC,
valid_from TIMESTAMPTZ,
valid_to TIMESTAMPTZ,
usage_limit NUMERIC,
used_count NUMERIC,
is_active BOOLEAN,
premium_only BOOLEAN,
is_featured BOOLEAN,
is_limited_time BOOLEAN,
terms_conditions TEXT,
eligible_branch_ids TEXT,
redemption_requirements TEXT,
view_count NUMERIC,
sort_order NUMERIC,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Dispute -> Table: disputes
-- ============================================================
CREATE TABLE IF NOT EXISTS disputes (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
user_id TEXT,
user_name TEXT,
business_id TEXT,
business_name TEXT,
business_owner_id TEXT,
transaction_id TEXT,
qr_code_id TEXT,
reason TEXT,
description TEXT,
evidence_urls TEXT,
status TEXT,
business_response TEXT,
business_responded_at TIMESTAMPTZ,
resolution_notes TEXT,
refund_amount NUMERIC,
refund_issued BOOLEAN,
sla_due_at TIMESTAMPTZ,
escalated_at TIMESTAMPTZ,
resolved_at TIMESTAMPTZ,
resolved_by_id TEXT,
timeline TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Employee -> Table: employees
-- ============================================================
CREATE TABLE IF NOT EXISTS employees (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
business_id TEXT,
business_name TEXT,
user_id TEXT,
full_name TEXT,
email TEXT,
phone TEXT,
role TEXT,
permissions TEXT,
is_active BOOLEAN,
hired_date TIMESTAMPTZ,
branch_id TEXT,
branch_name TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: EmployeeSchedule -> Table: employee_schedules
-- ============================================================
CREATE TABLE IF NOT EXISTS employee_schedules (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
employee_id TEXT,
employee_name TEXT,
business_id TEXT,
business_name TEXT,
branch_id TEXT,
branch_name TEXT,
weekday TEXT,
start_time TEXT,
end_time TEXT,
break_minutes NUMERIC,
is_recurring BOOLEAN,
specific_date TIMESTAMPTZ,
clock_in_time TIMESTAMPTZ,
clock_out_time TIMESTAMPTZ,
status TEXT,
notes TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Favorite -> Table: favorites
-- ============================================================
CREATE TABLE IF NOT EXISTS favorites (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
user_id TEXT,
user_name TEXT,
business_id TEXT,
business_name TEXT,
category TEXT,
discount_id TEXT,
discount_title TEXT,
collection_name TEXT,
notify_on_change BOOLEAN,
is_watched BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: FeatureFlag -> Table: feature_flags
-- ============================================================
CREATE TABLE IF NOT EXISTS feature_flags (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
name TEXT,
description TEXT,
key TEXT,
is_enabled BOOLEAN,
rollout_strategy TEXT,
target_countries TEXT,
target_user_groups TEXT,
rollout_percentage NUMERIC,
scheduled_activation_at TIMESTAMPTZ,
scheduled_deactivation_at TIMESTAMPTZ,
created_by_id TEXT,
created_by_name TEXT,
updated_by_id TEXT,
updated_by_name TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: GiftCampaign -> Table: gift_campaigns
-- ============================================================
CREATE TABLE IF NOT EXISTS gift_campaigns (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
business_id TEXT,
business_name TEXT,
title TEXT,
description TEXT,
gift_type TEXT,
value NUMERIC,
value_unit TEXT,
trigger_type TEXT,
audience_type TEXT,
target_user_ids TEXT,
segment_rules TEXT,
milestone_metric TEXT,
milestone_threshold NUMERIC,
valid_from TIMESTAMPTZ,
valid_to TIMESTAMPTZ,
expiry_days NUMERIC,
total_quantity NUMERIC,
claimed_quantity NUMERIC,
redeemed_quantity NUMERIC,
per_customer_limit NUMERIC,
points_reward NUMERIC,
status TEXT,
image_url TEXT,
scheduled_at TIMESTAMPTZ,
sent_count NUMERIC,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: GiftRedemption -> Table: gift_redemptions
-- ============================================================
CREATE TABLE IF NOT EXISTS gift_redemptions (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
gift_campaign_id TEXT,
gift_campaign_title TEXT,
user_id TEXT,
user_name TEXT,
business_id TEXT,
business_name TEXT,
awarded_date TIMESTAMPTZ,
redeemed_date TIMESTAMPTZ,
expiry_date TIMESTAMPTZ,
status TEXT,
redemption_code TEXT,
gift_type_snapshot TEXT,
gift_value_snapshot NUMERIC,
gift_value_unit_snapshot TEXT,
source TEXT,
points_awarded NUMERIC,
transaction_id TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Invoice -> Table: invoices
-- ============================================================
CREATE TABLE IF NOT EXISTS invoices (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
user_id TEXT,
user_name TEXT,
business_id TEXT,
business_name TEXT,
payment_id TEXT,
subscription_id TEXT,
invoice_number TEXT,
amount NUMERIC,
currency TEXT,
tax_rate NUMERIC,
tax_amount NUMERIC,
total_amount NUMERIC,
billing_period TEXT,
status TEXT,
issue_date TIMESTAMPTZ,
due_date TIMESTAMPTZ,
paid_date TIMESTAMPTZ,
pdf_url TEXT,
line_items TEXT,
refund_amount NUMERIC,
refunded_at TIMESTAMPTZ,
refund_reason TEXT,
notes TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: KnowledgeBase -> Table: knowledge_bases
-- ============================================================
CREATE TABLE IF NOT EXISTS knowledge_bases (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
title TEXT,
content TEXT,
summary TEXT,
category TEXT,
subcategory TEXT,
article_type TEXT,
tags TEXT,
is_published BOOLEAN,
is_featured BOOLEAN,
status TEXT,
language TEXT,
video_url TEXT,
screenshots TEXT,
sort_order NUMERIC,
version NUMERIC,
approved_by_id TEXT,
approved_by_name TEXT,
approved_at TIMESTAMPTZ,
translation_key TEXT,
view_count NUMERIC,
helpful_count NUMERIC,
unhelpful_count NUMERIC,
author_id TEXT,
author_name TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: LoyaltyPoint -> Table: loyalty_points
-- ============================================================
CREATE TABLE IF NOT EXISTS loyalty_points (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
user_id TEXT,
user_name TEXT,
business_id TEXT,
business_name TEXT,
points NUMERIC,
points_before NUMERIC,
balance_after NUMERIC,
level_after TEXT,
transaction_type TEXT,
description TEXT,
reference_id TEXT,
reference_type TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: LoyaltyTier -> Table: loyalty_tiers
-- ============================================================
CREATE TABLE IF NOT EXISTS loyalty_tiers (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
business_id TEXT,
business_name TEXT,
level_name TEXT,
min_points NUMERIC,
max_points NUMERIC,
color TEXT,
icon TEXT,
benefits TEXT,
points_multiplier NUMERIC,
discount_bonus NUMERIC,
priority_support BOOLEAN,
free_monthly_gift BOOLEAN,
sort_order NUMERIC,
is_active BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: MembershipPlan -> Table: membership_plans
-- ============================================================
CREATE TABLE IF NOT EXISTS membership_plans (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
name TEXT,
description TEXT,
plan_type TEXT,
price NUMERIC,
original_price NUMERIC,
currency TEXT,
billing_cycle TEXT,
features TEXT,
feature_entitlements TEXT,
trial_days NUMERIC,
is_promotional BOOLEAN,
is_active BOOLEAN,
is_archived BOOLEAN,
archived_at TIMESTAMPTZ,
sort_order NUMERIC,
max_discount_percentage NUMERIC,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: NewsletterSubscriber -> Table: newsletter_subscribers
-- ============================================================
CREATE TABLE IF NOT EXISTS newsletter_subscribers (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
email TEXT,
name TEXT,
source TEXT,
is_active BOOLEAN,
subscribed_at TIMESTAMPTZ,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: Notification -> Table: notifications
-- ============================================================
CREATE TABLE IF NOT EXISTS notifications (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
user_id TEXT,
title TEXT,
message TEXT,
type TEXT,
priority TEXT,
is_read BOOLEAN,
is_archived BOOLEAN,
action_url TEXT,
action_label TEXT,
channel TEXT,
sent_at TIMESTAMPTZ,
read_at TIMESTAMPTZ,
clicked_at TIMESTAMPTZ,
image_url TEXT,
business_id TEXT,
business_name TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: NotificationTemplate -> Table: notification_templates
-- ============================================================
CREATE TABLE IF NOT EXISTS notification_templates (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
name TEXT,
key TEXT,
channel TEXT,
subject TEXT,
body TEXT,
variables TEXT,
language TEXT,
is_active BOOLEAN,
version NUMERIC,
previous_body TEXT,
previous_subject TEXT,
previous_version NUMERIC,
created_by_id TEXT,
created_by_name TEXT,
updated_by_id TEXT,
updated_by_name TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: OtpCode -> Table: otp_codes
-- ============================================================
CREATE TABLE IF NOT EXISTS otp_codes (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
description TEXT,
user_id TEXT,
phone_number TEXT,
code_hash TEXT,
delivery_method TEXT,
expires_at TIMESTAMPTZ,
attempts NUMERIC,
verified BOOLEAN,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);
-- ============================================================
-- Entity: OutreachCampaign -> Table: outreach_campaigns
-- ============================================================
CREATE TABLE IF NOT EXISTS outreach_campaigns (
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
title TEXT,
description TEXT,
target_category TEXT,
target_city TEXT,
target_country TEXT,
email_subject TEXT,
email_body TEXT,
recipients TEXT,
status TEXT,
total_recipients NUMERIC,
sent_count NUMERIC,
failed_count NUMERIC,
response_count NUMERIC,
sent_at TIMESTAMPTZ,
created_by_name TEXT,
created_date TIMESTAMPTZ DEFAULT now(),
updated_date TIMESTAMPTZ DEFAULT now(),
created_by TEXT
);