forked from SeungpilPark/uEngine-bill
-
Notifications
You must be signed in to change notification settings - Fork 7
/
uengine-bill-all.sql
2978 lines (2841 loc) · 135 KB
/
uengine-bill-all.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
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
/*! USE killbill */;
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS accounts;
CREATE TABLE accounts (
record_id serial unique,
id varchar(36) NOT NULL,
external_key varchar(255) NULL,
email varchar(128) DEFAULT NULL,
name varchar(100) DEFAULT NULL,
first_name_length int DEFAULT NULL,
currency varchar(3) DEFAULT NULL,
billing_cycle_day_local int DEFAULT NULL,
parent_account_id varchar(36) DEFAULT NULL,
is_payment_delegated_to_parent boolean DEFAULT FALSE,
payment_method_id varchar(36) DEFAULT NULL,
time_zone varchar(50) NOT NULL,
locale varchar(5) DEFAULT NULL,
address1 varchar(100) DEFAULT NULL,
address2 varchar(100) DEFAULT NULL,
company_name varchar(50) DEFAULT NULL,
city varchar(50) DEFAULT NULL,
state_or_province varchar(50) DEFAULT NULL,
country varchar(50) DEFAULT NULL,
postal_code varchar(16) DEFAULT NULL,
phone varchar(25) DEFAULT NULL,
notes varchar(4096) DEFAULT NULL,
migrated boolean default false,
is_notified_for_invoices boolean NOT NULL,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX accounts_id ON accounts(id);
CREATE UNIQUE INDEX accounts_external_key ON accounts(external_key, tenant_record_id);
CREATE INDEX accounts_tenant_record_id ON accounts(tenant_record_id);
DROP TABLE IF EXISTS account_history;
CREATE TABLE account_history (
record_id serial unique,
id varchar(36) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
external_key varchar(255) NULL,
email varchar(128) DEFAULT NULL,
name varchar(100) DEFAULT NULL,
first_name_length int DEFAULT NULL,
currency varchar(3) DEFAULT NULL,
billing_cycle_day_local int DEFAULT NULL,
parent_account_id varchar(36) DEFAULT NULL,
payment_method_id varchar(36) DEFAULT NULL,
is_payment_delegated_to_parent boolean default false,
time_zone varchar(50) NOT NULL,
locale varchar(5) DEFAULT NULL,
address1 varchar(100) DEFAULT NULL,
address2 varchar(100) DEFAULT NULL,
company_name varchar(50) DEFAULT NULL,
city varchar(50) DEFAULT NULL,
state_or_province varchar(50) DEFAULT NULL,
country varchar(50) DEFAULT NULL,
postal_code varchar(16) DEFAULT NULL,
phone varchar(25) DEFAULT NULL,
notes varchar(4096) DEFAULT NULL,
migrated boolean default false,
is_notified_for_invoices boolean NOT NULL,
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX account_history_target_record_id ON account_history(target_record_id);
CREATE INDEX account_history_tenant_record_id ON account_history(tenant_record_id);
DROP TABLE IF EXISTS account_emails;
CREATE TABLE account_emails (
record_id serial unique,
id varchar(36) NOT NULL,
account_id varchar(36) NOT NULL,
email varchar(128) NOT NULL,
is_active boolean default true,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX account_email_id ON account_emails(id);
CREATE INDEX account_email_account_id_email ON account_emails(account_id, email);
CREATE INDEX account_emails_tenant_account_record_id ON account_emails(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS account_email_history;
CREATE TABLE account_email_history (
record_id serial unique,
id varchar(36) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
account_id varchar(36) NOT NULL,
email varchar(128) NOT NULL,
is_active boolean default true,
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX account_email_target_record_id ON account_email_history(target_record_id);
CREATE INDEX account_email_history_tenant_account_record_id ON account_email_history(tenant_record_id, account_record_id);
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS bus_ext_events;
CREATE TABLE bus_ext_events (
record_id serial unique,
class_name varchar(128) NOT NULL,
event_json varchar(2048) NOT NULL,
user_token varchar(36),
created_date datetime NOT NULL,
creating_owner varchar(50) NOT NULL,
processing_owner varchar(50) DEFAULT NULL,
processing_available_date datetime DEFAULT NULL,
processing_state varchar(14) DEFAULT 'AVAILABLE',
error_count int /*! unsigned */ DEFAULT 0,
/* Note: account_record_id can be NULL (e.g. TagDefinition events) */
search_key1 bigint /*! unsigned */ default null,
search_key2 bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX idx_bus_ext_where ON bus_ext_events (processing_state, processing_owner, processing_available_date);
CREATE INDEX bus_ext_events_tenant_account_record_id ON bus_ext_events(search_key2, search_key1);
DROP TABLE IF EXISTS bus_ext_events_history;
CREATE TABLE bus_ext_events_history (
record_id serial unique,
class_name varchar(128) NOT NULL,
event_json varchar(2048) NOT NULL,
user_token varchar(36),
created_date datetime NOT NULL,
creating_owner varchar(50) NOT NULL,
processing_owner varchar(50) DEFAULT NULL,
processing_available_date datetime DEFAULT NULL,
processing_state varchar(14) DEFAULT 'AVAILABLE',
error_count int /*! unsigned */ DEFAULT 0,
/* Note: account_record_id can be NULL (e.g. TagDefinition events) */
search_key1 bigint /*! unsigned */ default null,
search_key2 bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS catalog_override_plan_definition;
CREATE TABLE catalog_override_plan_definition (
record_id serial unique,
parent_plan_name varchar(255) NOT NULL,
effective_date datetime NOT NULL,
is_active boolean default true,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX catalog_override_plan_definition_tenant_record_id ON catalog_override_plan_definition(tenant_record_id);
DROP TABLE IF EXISTS catalog_override_phase_definition;
CREATE TABLE catalog_override_phase_definition (
record_id serial unique,
parent_phase_name varchar(255) NOT NULL,
currency varchar(3) NOT NULL,
fixed_price numeric(15,9) NULL,
recurring_price numeric(15,9) NULL,
effective_date datetime NOT NULL,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX catalog_override_phase_definition_idx ON catalog_override_phase_definition(tenant_record_id, parent_phase_name, currency);
DROP TABLE IF EXISTS catalog_override_plan_phase;
CREATE TABLE catalog_override_plan_phase (
record_id serial unique,
phase_number smallint /*! unsigned */ NOT NULL,
phase_def_record_id bigint /*! unsigned */ not null,
target_plan_def_record_id bigint /*! unsigned */ not null,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX catalog_override_plan_phase_idx ON catalog_override_plan_phase(tenant_record_id, phase_number, phase_def_record_id);
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS subscription_events;
CREATE TABLE subscription_events (
record_id serial unique,
id varchar(36) NOT NULL,
event_type varchar(15) NOT NULL,
user_type varchar(25) DEFAULT NULL,
effective_date datetime NOT NULL,
subscription_id varchar(36) NOT NULL,
plan_name varchar(255) DEFAULT NULL,
phase_name varchar(255) DEFAULT NULL,
price_list_name varchar(64) DEFAULT NULL,
billing_cycle_day_local int DEFAULT NULL,
is_active boolean default true,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX subscription_events_id ON subscription_events(id);
CREATE INDEX idx_ent_1 ON subscription_events(subscription_id, is_active, effective_date);
CREATE INDEX idx_ent_2 ON subscription_events(subscription_id, effective_date, created_date, id);
CREATE INDEX subscription_events_tenant_account_record_id ON subscription_events(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS subscriptions;
CREATE TABLE subscriptions (
record_id serial unique,
id varchar(36) NOT NULL,
bundle_id varchar(36) NOT NULL,
category varchar(32) NOT NULL,
start_date datetime NOT NULL,
bundle_start_date datetime NOT NULL,
charged_through_date datetime DEFAULT NULL,
migrated bool NOT NULL default FALSE,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX subscriptions_id ON subscriptions(id);
CREATE INDEX subscriptions_bundle_id ON subscriptions(bundle_id);
CREATE INDEX subscriptions_tenant_account_record_id ON subscriptions(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS bundles;
CREATE TABLE bundles (
record_id serial unique,
id varchar(36) NOT NULL,
external_key varchar(255) NOT NULL,
account_id varchar(36) NOT NULL,
last_sys_update_date datetime,
original_created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX bundles_id ON bundles(id);
CREATE INDEX bundles_key ON bundles(external_key);
CREATE INDEX bundles_account ON bundles(account_id);
CREATE INDEX bundles_tenant_account_record_id ON bundles(tenant_record_id, account_record_id);
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS blocking_states;
CREATE TABLE blocking_states (
record_id serial unique,
id varchar(36) NOT NULL,
blockable_id varchar(36) NOT NULL,
type varchar(20) NOT NULL,
state varchar(50) NOT NULL,
service varchar(20) NOT NULL,
block_change bool NOT NULL,
block_entitlement bool NOT NULL,
block_billing bool NOT NULL,
effective_date datetime NOT NULL,
is_active boolean default true,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX blocking_states_id ON blocking_states(blockable_id);
CREATE INDEX blocking_states_tenant_account_record_id ON blocking_states(tenant_record_id, account_record_id);
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS invoice_items;
CREATE TABLE invoice_items (
record_id serial unique,
id varchar(36) NOT NULL,
type varchar(24) NOT NULL,
invoice_id varchar(36) NOT NULL,
account_id varchar(36) NOT NULL,
child_account_id varchar(36),
bundle_id varchar(36),
subscription_id varchar(36),
description varchar(255),
plan_name varchar(255),
phase_name varchar(255),
usage_name varchar(255),
start_date date,
end_date date,
amount numeric(15,9) NOT NULL,
rate numeric(15,9) NULL,
currency varchar(3) NOT NULL,
linked_item_id varchar(36),
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX invoice_items_id ON invoice_items(id);
CREATE INDEX invoice_items_subscription_id ON invoice_items(subscription_id ASC);
CREATE INDEX invoice_items_invoice_id ON invoice_items(invoice_id ASC);
CREATE INDEX invoice_items_account_id ON invoice_items(account_id ASC);
CREATE INDEX invoice_items_linked_item_id ON invoice_items(linked_item_id ASC);
CREATE INDEX invoice_items_tenant_account_record_id ON invoice_items(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS invoices;
CREATE TABLE invoices (
record_id serial unique,
id varchar(36) NOT NULL,
account_id varchar(36) NOT NULL,
invoice_date date NOT NULL,
target_date date,
currency varchar(3) NOT NULL,
status varchar(15) NOT NULL DEFAULT 'COMMITTED',
migrated bool NOT NULL,
parent_invoice bool NOT NULL DEFAULT FALSE,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX invoices_id ON invoices(id);
CREATE INDEX invoices_account ON invoices(account_id ASC);
CREATE INDEX invoices_tenant_account_record_id ON invoices(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS invoice_payments;
CREATE TABLE invoice_payments (
record_id serial unique,
id varchar(36) NOT NULL,
type varchar(24) NOT NULL,
invoice_id varchar(36) NOT NULL,
payment_id varchar(36),
payment_date datetime NOT NULL,
amount numeric(15,9) NOT NULL,
currency varchar(3) NOT NULL,
processed_currency varchar(3) NOT NULL,
payment_cookie_id varchar(255) DEFAULT NULL,
linked_invoice_payment_id varchar(36) DEFAULT NULL,
success bool DEFAULT true,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX invoice_payments_id ON invoice_payments(id);
CREATE INDEX invoice_payments_invoice_id ON invoice_payments(invoice_id);
CREATE INDEX invoice_payments_reversals ON invoice_payments(linked_invoice_payment_id);
CREATE INDEX invoice_payments_tenant_account_record_id ON invoice_payments(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS invoice_parent_children;
CREATE TABLE invoice_parent_children (
record_id serial unique,
id varchar(36) NOT NULL,
parent_invoice_id varchar(36) NOT NULL,
child_invoice_id varchar(36) NOT NULL,
child_account_id varchar(36) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX invoice_parent_children_id ON invoice_parent_children(id);
CREATE INDEX invoice_parent_children_invoice_id ON invoice_parent_children(parent_invoice_id);
CREATE INDEX invoice_parent_children_tenant_account_record_id ON invoice_parent_children(tenant_record_id, account_record_id);
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS payment_attempts;
CREATE TABLE payment_attempts (
record_id serial unique,
id varchar(36) NOT NULL,
account_id varchar(36) NOT NULL,
payment_method_id varchar(36) DEFAULT NULL,
payment_external_key varchar(255) NOT NULL,
transaction_id varchar(36),
transaction_external_key varchar(255) NOT NULL,
transaction_type varchar(32) NOT NULL,
state_name varchar(32) NOT NULL,
amount numeric(15,9),
currency varchar(3),
plugin_name varchar(1024) NOT NULL,
plugin_properties mediumblob,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY (record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX payment_attempts_id ON payment_attempts(id);
CREATE INDEX payment_attempts_payment ON payment_attempts(transaction_id);
CREATE INDEX payment_attempts_payment_key ON payment_attempts(payment_external_key);
CREATE INDEX payment_attempts_payment_state ON payment_attempts(state_name);
CREATE INDEX payment_attempts_payment_transaction_key ON payment_attempts(transaction_external_key);
CREATE INDEX payment_attempts_tenant_account_record_id ON payment_attempts(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_attempt_history;
CREATE TABLE payment_attempt_history (
record_id serial unique,
id varchar(36) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
account_id varchar(36) NOT NULL,
payment_method_id varchar(36) DEFAULT NULL,
payment_external_key varchar(255) NOT NULL,
transaction_id varchar(36),
transaction_external_key varchar(255) NOT NULL,
transaction_type varchar(32) NOT NULL,
state_name varchar(32) NOT NULL,
amount numeric(15,9),
currency varchar(3),
plugin_name varchar(1024) NOT NULL,
plugin_properties mediumblob,
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX payment_attempt_history_target_record_id ON payment_attempt_history(target_record_id);
CREATE INDEX payment_attempt_history_tenant_account_record_id ON payment_attempt_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_methods;
CREATE TABLE payment_methods (
record_id serial unique,
id varchar(36) NOT NULL,
external_key varchar(255) NOT NULL,
account_id varchar(36) NOT NULL,
plugin_name varchar(50) NOT NULL,
is_active boolean default true,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY (record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX payment_methods_id ON payment_methods(id);
CREATE UNIQUE INDEX payment_methods_external_key ON payment_methods(external_key, tenant_record_id);
CREATE INDEX payment_methods_plugin_name ON payment_methods(plugin_name);
CREATE INDEX payment_methods_tenant_account_record_id ON payment_methods(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_method_history;
CREATE TABLE payment_method_history (
record_id serial unique,
id varchar(36) NOT NULL,
external_key varchar(255) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
account_id varchar(36) NOT NULL,
plugin_name varchar(50) NOT NULL,
is_active boolean default true,
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX payment_method_history_target_record_id ON payment_method_history(target_record_id);
CREATE INDEX payment_method_history_tenant_account_record_id ON payment_method_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payments;
CREATE TABLE payments (
record_id serial unique,
id varchar(36) NOT NULL,
account_id varchar(36) NOT NULL,
payment_method_id varchar(36) NOT NULL,
external_key varchar(255) NOT NULL,
state_name varchar(64) DEFAULT NULL,
last_success_state_name varchar(64) DEFAULT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY (record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX payments_id ON payments(id);
CREATE UNIQUE INDEX payments_key ON payments(external_key, tenant_record_id);
CREATE INDEX payments_accnt ON payments(account_id);
CREATE INDEX payments_tenant_account_record_id ON payments(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_history;
CREATE TABLE payment_history (
record_id serial unique,
id varchar(36) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
account_id varchar(36) NOT NULL,
payment_method_id varchar(36) NOT NULL,
external_key varchar(255) NOT NULL,
state_name varchar(64) DEFAULT NULL,
last_success_state_name varchar(64) DEFAULT NULL,
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX payment_history_target_record_id ON payment_history(target_record_id);
CREATE INDEX payment_history_tenant_account_record_id ON payment_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_transactions;
CREATE TABLE payment_transactions (
record_id serial unique,
id varchar(36) NOT NULL,
attempt_id varchar(36) DEFAULT NULL,
transaction_external_key varchar(255) NOT NULL,
transaction_type varchar(32) NOT NULL,
effective_date datetime NOT NULL,
transaction_status varchar(50) NOT NULL,
amount numeric(15,9),
currency varchar(3),
processed_amount numeric(15,9),
processed_currency varchar(3),
payment_id varchar(36) NOT NULL,
gateway_error_code varchar(32),
gateway_error_msg varchar(256),
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY (record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX transactions_id ON payment_transactions(id);
CREATE INDEX transactions_payment_id ON payment_transactions(payment_id);
CREATE INDEX transactions_key ON payment_transactions(transaction_external_key);
CREATE INDEX transactions_status ON payment_transactions(transaction_status);
CREATE INDEX transactions_tenant_account_record_id ON payment_transactions(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_transaction_history;
CREATE TABLE payment_transaction_history (
record_id serial unique,
id varchar(36) NOT NULL,
attempt_id varchar(36) DEFAULT NULL,
transaction_external_key varchar(255) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
transaction_type varchar(32) NOT NULL,
effective_date datetime NOT NULL,
transaction_status varchar(50) NOT NULL,
amount numeric(15,9),
currency varchar(3),
processed_amount numeric(15,9),
processed_currency varchar(3),
payment_id varchar(36) NOT NULL,
gateway_error_code varchar(32),
gateway_error_msg varchar(256),
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY (record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX transaction_history_target_record_id ON payment_transaction_history(target_record_id);
CREATE INDEX transaction_history_tenant_account_record_id ON payment_transaction_history(tenant_record_id, account_record_id);
/* PaymentControlPlugin lives here until this becomes a first class citizen plugin */
DROP TABLE IF EXISTS _invoice_payment_control_plugin_auto_pay_off;
CREATE TABLE _invoice_payment_control_plugin_auto_pay_off (
record_id serial unique,
attempt_id varchar(36) NOT NULL,
payment_external_key varchar(255) NOT NULL,
transaction_external_key varchar(255) NOT NULL,
account_id varchar(36) NOT NULL,
plugin_name varchar(50) NOT NULL,
payment_id varchar(36),
payment_method_id varchar(36) NOT NULL,
amount numeric(15,9),
currency varchar(3),
is_active boolean default true,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
PRIMARY KEY (record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX _invoice_payment_control_plugin_auto_pay_off_account ON _invoice_payment_control_plugin_auto_pay_off(account_id);
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS rolled_up_usage;
CREATE TABLE rolled_up_usage (
record_id serial unique,
id varchar(36) NOT NULL,
subscription_id varchar(36) NOT NULL,
unit_type varchar(255) NOT NULL,
record_date date NOT NULL,
amount bigint NOT NULL,
tracking_id varchar(128) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX rolled_up_usage_id ON rolled_up_usage(id);
CREATE INDEX rolled_up_usage_subscription_id ON rolled_up_usage(subscription_id ASC);
CREATE INDEX rolled_up_usage_tenant_account_record_id ON rolled_up_usage(tenant_record_id, account_record_id);
CREATE INDEX rolled_up_usage_account_record_id ON rolled_up_usage(account_record_id);
CREATE INDEX rolled_up_usage_tracking_id_subscription_id_tenant_record_id ON rolled_up_usage(tracking_id, subscription_id, tenant_record_id);
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS custom_fields;
CREATE TABLE custom_fields (
record_id serial unique,
id varchar(36) NOT NULL,
object_id varchar(36) NOT NULL,
object_type varchar(30) NOT NULL,
is_active boolean default true,
field_name varchar(64) NOT NULL,
field_value varchar(255),
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) DEFAULT NULL,
updated_date datetime DEFAULT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX custom_fields_id ON custom_fields(id);
CREATE INDEX custom_fields_object_id_object_type ON custom_fields(object_id, object_type);
CREATE INDEX custom_fields_tenant_account_record_id ON custom_fields(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS custom_field_history;
CREATE TABLE custom_field_history (
record_id serial unique,
id varchar(36) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
object_id varchar(36) NOT NULL,
object_type varchar(30) NOT NULL,
is_active boolean default true,
field_name varchar(64),
field_value varchar(255),
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX custom_field_history_target_record_id ON custom_field_history(target_record_id);
CREATE INDEX custom_field_history_object_id_object_type ON custom_fields(object_id, object_type);
CREATE INDEX custom_field_history_tenant_account_record_id ON custom_field_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS tag_definitions;
CREATE TABLE tag_definitions (
record_id serial unique,
id varchar(36) NOT NULL,
name varchar(20) NOT NULL,
description varchar(200) NOT NULL,
is_active boolean default true,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX tag_definitions_id ON tag_definitions(id);
CREATE INDEX tag_definitions_tenant_record_id ON tag_definitions(tenant_record_id);
DROP TABLE IF EXISTS tag_definition_history;
CREATE TABLE tag_definition_history (
record_id serial unique,
id varchar(36) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
name varchar(30) NOT NULL,
description varchar(200),
is_active boolean default true,
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
/* Note: there is no account_record_id to populate */
account_record_id bigint /*! unsigned */ default null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX tag_definition_history_id ON tag_definition_history(id);
CREATE INDEX tag_definition_history_target_record_id ON tag_definition_history(target_record_id);
CREATE INDEX tag_definition_history_name ON tag_definition_history(name);
CREATE INDEX tag_definition_history_tenant_record_id ON tag_definition_history(tenant_record_id);
DROP TABLE IF EXISTS tags;
CREATE TABLE tags (
record_id serial unique,
id varchar(36) NOT NULL,
tag_definition_id varchar(36) NOT NULL,
object_id varchar(36) NOT NULL,
object_type varchar(30) NOT NULL,
is_active boolean default true,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX tags_id ON tags(id);
CREATE INDEX tags_by_object ON tags(object_id);
CREATE INDEX tags_tenant_account_record_id ON tags(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS tag_history;
CREATE TABLE tag_history (
record_id serial unique,
id varchar(36) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
object_id varchar(36) NOT NULL,
object_type varchar(30) NOT NULL,
tag_definition_id varchar(36) NOT NULL,
is_active boolean default true,
change_type varchar(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
account_record_id bigint /*! unsigned */ not null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX tag_history_target_record_id ON tag_history(target_record_id);
CREATE INDEX tag_history_by_object ON tags(object_id);
CREATE INDEX tag_history_tenant_account_record_id ON tag_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS audit_log;
CREATE TABLE audit_log (
record_id serial unique,
id varchar(36) NOT NULL,
target_record_id bigint /*! unsigned */ not null,
table_name varchar(50) NOT NULL,
change_type varchar(6) NOT NULL,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
reason_code varchar(255) DEFAULT NULL,
comments varchar(255) DEFAULT NULL,
user_token varchar(36),
/* Note: can be NULL (e.g. tenant_kvs audits) */
account_record_id bigint /*! unsigned */ default null,
tenant_record_id bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX audit_log_fetch_target_record_id ON audit_log(table_name, target_record_id);
CREATE INDEX audit_log_user_name ON audit_log(created_by);
CREATE INDEX audit_log_tenant_account_record_id ON audit_log(tenant_record_id, account_record_id);
CREATE INDEX audit_log_via_history ON audit_log(target_record_id, table_name, tenant_record_id);
DROP TABLE IF EXISTS notifications;
CREATE TABLE notifications (
record_id serial unique,
class_name varchar(256) NOT NULL,
event_json varchar(2048) NOT NULL,
user_token varchar(36),
created_date datetime NOT NULL,
creating_owner varchar(50) NOT NULL,
processing_owner varchar(50) DEFAULT NULL,
processing_available_date datetime DEFAULT NULL,
processing_state varchar(14) DEFAULT 'AVAILABLE',
error_count int /*! unsigned */ DEFAULT 0,
search_key1 bigint /*! unsigned */ not null,
search_key2 bigint /*! unsigned */ not null default 0,
queue_name varchar(64) NOT NULL,
effective_date datetime NOT NULL,
future_user_token varchar(36),
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX idx_comp_where ON notifications (effective_date, processing_state, processing_owner, processing_available_date);
CREATE INDEX idx_update ON notifications (processing_state, processing_owner, processing_available_date);
CREATE INDEX idx_get_ready ON notifications (effective_date, created_date);
CREATE INDEX notifications_tenant_account_record_id ON notifications(search_key2, search_key1);
DROP TABLE IF EXISTS notifications_history;
CREATE TABLE notifications_history (
record_id serial unique,
class_name varchar(256) NOT NULL,
event_json varchar(2048) NOT NULL,
user_token varchar(36),
created_date datetime NOT NULL,
creating_owner varchar(50) NOT NULL,
processing_owner varchar(50) DEFAULT NULL,
processing_available_date datetime DEFAULT NULL,
processing_state varchar(14) DEFAULT 'AVAILABLE',
error_count int /*! unsigned */ DEFAULT 0,
search_key1 bigint /*! unsigned */ not null,
search_key2 bigint /*! unsigned */ not null default 0,
queue_name varchar(64) NOT NULL,
effective_date datetime NOT NULL,
future_user_token varchar(36),
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
DROP TABLE IF EXISTS bus_events;
CREATE TABLE bus_events (
record_id serial unique,
class_name varchar(128) NOT NULL,
event_json varchar(2048) NOT NULL,
user_token varchar(36),
created_date datetime NOT NULL,
creating_owner varchar(50) NOT NULL,
processing_owner varchar(50) DEFAULT NULL,
processing_available_date datetime DEFAULT NULL,
processing_state varchar(14) DEFAULT 'AVAILABLE',
error_count int /*! unsigned */ DEFAULT 0,
/* Note: account_record_id can be NULL (e.g. TagDefinition events) */
search_key1 bigint /*! unsigned */ default null,
search_key2 bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX idx_bus_where ON bus_events (processing_state, processing_owner, processing_available_date);
CREATE INDEX bus_events_tenant_account_record_id ON bus_events(search_key2, search_key1);
DROP TABLE IF EXISTS bus_events_history;
CREATE TABLE bus_events_history (
record_id serial unique,
class_name varchar(128) NOT NULL,
event_json varchar(2048) NOT NULL,
user_token varchar(36),
created_date datetime NOT NULL,
creating_owner varchar(50) NOT NULL,
processing_owner varchar(50) DEFAULT NULL,
processing_available_date datetime DEFAULT NULL,
processing_state varchar(14) DEFAULT 'AVAILABLE',
error_count int /*! unsigned */ DEFAULT 0,
/* Note: account_record_id can be NULL (e.g. TagDefinition events) */
search_key1 bigint /*! unsigned */ default null,
search_key2 bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
drop table if exists sessions;
create table sessions (
record_id serial unique
, id varchar(36) NOT NULL
, start_timestamp datetime not null
, last_access_time datetime default null
, timeout int
, host varchar(100) default null
, session_data mediumblob default null
, primary key(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX sessions_id ON sessions(id);
DROP TABLE IF EXISTS users;
CREATE TABLE users (
record_id serial unique,
username varchar(128) NULL,
password varchar(128) NULL,
password_salt varchar(128) NULL,
is_active boolean default true,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX users_username ON users(username);
DROP TABLE IF EXISTS user_roles;
CREATE TABLE user_roles (
record_id serial unique,
username varchar(128) NULL,
role_name varchar(128) NULL,
is_active boolean default true,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX user_roles_idx ON user_roles(username, role_name);
DROP TABLE IF EXISTS roles_permissions;
CREATE TABLE roles_permissions (
record_id serial unique,
role_name varchar(128) NULL,
permission varchar(128) NULL,
is_active boolean default true,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX roles_permissions_idx ON roles_permissions(role_name, permission);
DROP TABLE IF EXISTS node_infos;
CREATE TABLE node_infos (
record_id serial unique,
node_name varchar(50) NOT NULL,
boot_date datetime NOT NULL,
updated_date datetime DEFAULT NULL,
node_info text NOT NULL,
is_active boolean default true,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX node_name_idx ON node_infos(node_name);
DROP TABLE IF EXISTS service_broadcasts;
CREATE TABLE service_broadcasts (
record_id serial unique,
service_name varchar(50) NOT NULL,
type varchar(64) NOT NULL,
event text NOT NULL,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
/*! SET default_storage_engine=INNODB */;
DROP TABLE IF EXISTS tenants;
CREATE TABLE tenants (
record_id serial unique,
id varchar(36) NOT NULL,
external_key varchar(255) NULL,
api_key varchar(128) NULL,
api_secret varchar(128) NULL,
api_salt varchar(128) NULL,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX tenants_id ON tenants(id);
CREATE UNIQUE INDEX tenants_api_key ON tenants(api_key);
DROP TABLE IF EXISTS tenant_kvs;
CREATE TABLE tenant_kvs (
record_id serial unique,
id varchar(36) NOT NULL,
tenant_record_id bigint /*! unsigned */ not null default 0,
tenant_key varchar(255) NOT NULL,
tenant_value mediumtext NOT NULL,
is_active boolean default true,
created_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,