-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathIdempotentApplyMigrations.sql
1452 lines (1310 loc) · 59 KB
/
IdempotentApplyMigrations.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
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
START TRANSACTION;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TYPE account_default_deposit_rule AS ENUM ('accept', 'reject', 'allow_existing');
CREATE TYPE account_resource_preference_rule AS ENUM ('allowed', 'disallowed');
CREATE TYPE authorized_depositor_badge_type AS ENUM ('resource', 'non_fungible');
CREATE TYPE entity_relationship AS ENUM ('component_to_instantiating_package', 'vault_to_resource', 'validator_to_stake_vault', 'validator_to_pending_xrd_withdraw_vault', 'validator_to_locked_owner_stake_unit_vault', 'validator_to_pending_owner_stake_unit_unlock_vault', 'stake_unit_of_validator', 'claim_token_of_validator', 'entity_to_royalty_vault', 'royalty_vault_of_entity', 'account_locker_of_locker', 'account_locker_of_account', 'resource_pool_to_unit_resource', 'resource_pool_to_resource', 'resource_pool_to_resource_vault', 'unit_resource_of_resource_pool', 'resource_vault_of_resource_pool', 'access_controller_to_recovery_badge', 'recovery_badge_of_access_controller');
CREATE TYPE entity_type AS ENUM ('global_consensus_manager', 'global_fungible_resource', 'global_non_fungible_resource', 'global_generic_component', 'internal_generic_component', 'global_account_component', 'global_package', 'internal_key_value_store', 'internal_fungible_vault', 'internal_non_fungible_vault', 'global_validator', 'global_access_controller', 'global_identity', 'global_one_resource_pool', 'global_two_resource_pool', 'global_multi_resource_pool', 'global_transaction_tracker', 'global_account_locker');
CREATE TYPE ledger_transaction_manifest_class AS ENUM ('general', 'transfer', 'validator_stake', 'validator_unstake', 'validator_claim', 'account_deposit_settings_update', 'pool_contribution', 'pool_redemption');
CREATE TYPE ledger_transaction_marker_event_type AS ENUM ('withdrawal', 'deposit');
CREATE TYPE ledger_transaction_marker_operation_type AS ENUM ('resource_in_use', 'account_deposited_into', 'account_withdrawn_from', 'account_owner_method_call', 'badge_presented');
CREATE TYPE ledger_transaction_marker_transaction_type AS ENUM ('user', 'round_change', 'genesis_flash', 'genesis_transaction', 'protocol_update_flash', 'protocol_update_transaction');
CREATE TYPE ledger_transaction_marker_type AS ENUM ('transaction_type', 'event', 'manifest_address', 'affected_global_entity', 'manifest_class', 'event_global_emitter', 'epoch_change');
CREATE TYPE ledger_transaction_status AS ENUM ('succeeded', 'failed');
CREATE TYPE ledger_transaction_type AS ENUM ('genesis', 'user', 'round_update', 'flash');
CREATE TYPE module_id AS ENUM ('main', 'metadata', 'royalty', 'role_assignment');
CREATE TYPE non_fungible_id_type AS ENUM ('string', 'integer', 'bytes', 'ruid');
CREATE TYPE package_vm_type AS ENUM ('native', 'scrypto_v1');
CREATE TYPE pending_transaction_intent_ledger_status AS ENUM ('unknown', 'committed', 'commit_pending', 'permanent_rejection', 'possible_to_commit', 'likely_but_not_certain_rejection');
CREATE TYPE pending_transaction_payload_ledger_status AS ENUM ('unknown', 'committed', 'commit_pending', 'clashing_commit', 'permanently_rejected', 'transiently_accepted', 'transiently_rejected');
CREATE TYPE public_key_type AS ENUM ('ecdsa_secp256k1', 'eddsa_ed25519');
CREATE TYPE resource_type AS ENUM ('fungible', 'non_fungible');
CREATE TYPE sbor_type_kind AS ENUM ('well_known', 'schema_local');
CREATE TYPE standard_metadata_key AS ENUM ('dapp_account_type', 'dapp_definition', 'dapp_definitions', 'dapp_claimed_websites', 'dapp_claimed_entities', 'dapp_account_locker');
CREATE TYPE state_type AS ENUM ('json', 'sbor');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE account_authorized_depositor_aggregate_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
account_entity_id bigint NOT NULL,
entry_ids bigint[] NOT NULL,
CONSTRAINT "PK_account_authorized_depositor_aggregate_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE account_authorized_depositor_entry_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
account_entity_id bigint NOT NULL,
is_deleted boolean NOT NULL,
discriminator authorized_depositor_badge_type NOT NULL,
resource_entity_id bigint,
non_fungible_id text,
CONSTRAINT "PK_account_authorized_depositor_entry_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE account_default_deposit_rule_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
account_entity_id bigint NOT NULL,
default_deposit_rule account_default_deposit_rule NOT NULL,
CONSTRAINT "PK_account_default_deposit_rule_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE account_locker_entry_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
account_locker_entity_id bigint NOT NULL,
account_entity_id bigint NOT NULL,
key_value_store_entity_id bigint NOT NULL,
CONSTRAINT "PK_account_locker_entry_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE account_locker_entry_resource_vault_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
account_locker_definition_id bigint NOT NULL,
resource_entity_id bigint NOT NULL,
vault_entity_id bigint NOT NULL,
CONSTRAINT "PK_account_locker_entry_resource_vault_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE account_locker_entry_touch_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
account_locker_definition_id bigint NOT NULL,
CONSTRAINT "PK_account_locker_entry_touch_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE account_resource_preference_rule_aggregate_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
account_entity_id bigint NOT NULL,
entry_ids bigint[] NOT NULL,
CONSTRAINT "PK_account_resource_preference_rule_aggregate_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE account_resource_preference_rule_entry_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
account_entity_id bigint NOT NULL,
resource_entity_id bigint NOT NULL,
account_resource_preference_rule account_resource_preference_rule,
is_deleted boolean NOT NULL,
CONSTRAINT "PK_account_resource_preference_rule_entry_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE component_method_royalty_aggregate_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
entry_ids bigint[] NOT NULL,
CONSTRAINT "PK_component_method_royalty_aggregate_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE component_method_royalty_entry_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
method_name text NOT NULL,
royalty_amount jsonb,
is_locked boolean NOT NULL,
CONSTRAINT "PK_component_method_royalty_entry_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entities (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
address text NOT NULL,
is_global boolean NOT NULL,
ancestor_ids bigint[],
parent_ancestor_id bigint,
owner_ancestor_id bigint,
global_ancestor_id bigint,
correlated_entity_relationships entity_relationship[] NOT NULL,
correlated_entity_ids bigint[] NOT NULL,
discriminator entity_type NOT NULL,
blueprint_name text,
blueprint_version text,
assigned_module_ids module_id[],
divisibility integer,
non_fungible_id_type non_fungible_id_type,
non_fungible_data_mutable_fields text[],
CONSTRAINT "PK_entities" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_metadata_entry_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
key text NOT NULL,
CONSTRAINT "PK_entity_metadata_entry_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_metadata_entry_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_metadata_entry_definition_id bigint NOT NULL,
value bytea,
is_deleted boolean NOT NULL,
is_locked boolean NOT NULL,
CONSTRAINT "PK_entity_metadata_entry_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_metadata_totals_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
total_entries_including_deleted bigint NOT NULL,
total_entries_excluding_deleted bigint NOT NULL,
CONSTRAINT "PK_entity_metadata_totals_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_resource_balance_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
resource_entity_id bigint NOT NULL,
balance numeric(1000) NOT NULL,
CONSTRAINT "PK_entity_resource_balance_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_resource_entry_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
resource_entity_id bigint NOT NULL,
resource_type resource_type NOT NULL,
CONSTRAINT "PK_entity_resource_entry_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_resource_totals_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
total_count bigint NOT NULL,
total_fungible_count bigint NOT NULL,
total_non_fungible_count bigint NOT NULL,
CONSTRAINT "PK_entity_resource_totals_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_resource_vault_entry_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
resource_entity_id bigint NOT NULL,
vault_entity_id bigint NOT NULL,
CONSTRAINT "PK_entity_resource_vault_entry_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_resource_vault_totals_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
resource_entity_id bigint NOT NULL,
total_count bigint NOT NULL,
CONSTRAINT "PK_entity_resource_vault_totals_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_role_assignments_aggregate_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
owner_role_id bigint NOT NULL,
entry_ids bigint[] NOT NULL,
CONSTRAINT "PK_entity_role_assignments_aggregate_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_role_assignments_entry_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
key_role text NOT NULL,
key_module module_id NOT NULL,
role_assignments jsonb,
is_deleted boolean NOT NULL,
CONSTRAINT "PK_entity_role_assignments_entry_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE entity_role_assignments_owner_role_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
role_assignments jsonb NOT NULL,
CONSTRAINT "PK_entity_role_assignments_owner_role_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE key_value_store_entry_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
key_value_store_entity_id bigint NOT NULL,
key bytea NOT NULL,
CONSTRAINT "PK_key_value_store_entry_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE key_value_store_entry_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
key_value_store_entry_definition_id bigint NOT NULL,
value bytea,
is_deleted boolean NOT NULL,
is_locked boolean NOT NULL,
CONSTRAINT "PK_key_value_store_entry_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE key_value_store_schema_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
key_value_store_entity_id bigint NOT NULL,
key_schema_hash bytea NOT NULL,
key_schema_defining_entity_id bigint NOT NULL,
key_sbor_type_kind sbor_type_kind NOT NULL,
key_type_index bigint NOT NULL,
value_schema_hash bytea NOT NULL,
value_schema_defining_entity_id bigint NOT NULL,
value_sbor_type_kind sbor_type_kind NOT NULL,
value_type_index bigint NOT NULL,
CONSTRAINT "PK_key_value_store_schema_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE key_value_store_totals_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
total_entries_including_deleted bigint NOT NULL,
total_entries_excluding_deleted bigint NOT NULL,
CONSTRAINT "PK_key_value_store_totals_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE ledger_transaction_events (
state_version bigint NOT NULL,
receipt_event_emitters jsonb[] NOT NULL,
receipt_event_names text[] NOT NULL,
receipt_event_sbors bytea[] NOT NULL,
receipt_event_schema_entity_ids bigint[] NOT NULL,
receipt_event_schema_hashes bytea[] NOT NULL,
receipt_event_type_indexes bigint[] NOT NULL,
receipt_event_sbor_type_kinds sbor_type_kind[] NOT NULL,
CONSTRAINT "PK_ledger_transaction_events" PRIMARY KEY (state_version)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE ledger_transaction_markers (
id bigint GENERATED BY DEFAULT AS IDENTITY,
state_version bigint NOT NULL,
discriminator ledger_transaction_marker_type NOT NULL,
entity_id bigint,
epoch_change boolean,
event_type ledger_transaction_marker_event_type,
resource_entity_id bigint,
quantity numeric(1000),
operation_type ledger_transaction_marker_operation_type,
manifest_class ledger_transaction_manifest_class,
is_most_specific boolean,
transaction_type ledger_transaction_marker_transaction_type,
CONSTRAINT "PK_ledger_transaction_markers" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE ledger_transactions (
state_version bigint NOT NULL,
epoch bigint NOT NULL,
round_in_epoch bigint NOT NULL,
index_in_epoch bigint NOT NULL,
index_in_round bigint NOT NULL,
fee_paid numeric(1000) NOT NULL,
tip_paid numeric(1000) NOT NULL,
affected_global_entities bigint[] NOT NULL,
round_timestamp timestamp with time zone NOT NULL,
created_timestamp timestamp with time zone NOT NULL,
normalized_round_timestamp timestamp with time zone NOT NULL,
receipt_status ledger_transaction_status NOT NULL,
receipt_fee_summary jsonb NOT NULL,
receipt_state_updates jsonb,
receipt_costing_parameters jsonb NOT NULL,
receipt_fee_source jsonb,
receipt_fee_destination jsonb,
receipt_next_epoch jsonb,
receipt_output jsonb,
receipt_error_message text,
balance_changes jsonb,
transaction_tree_hash text NOT NULL,
receipt_tree_hash text NOT NULL,
state_tree_hash text NOT NULL,
discriminator ledger_transaction_type NOT NULL,
payload_hash text,
intent_hash text,
signed_intent_hash text,
message jsonb,
raw_payload bytea,
manifest_instructions text,
manifest_classes ledger_transaction_manifest_class[],
CONSTRAINT "PK_ledger_transactions" PRIMARY KEY (state_version)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE non_fungible_id_data_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
non_fungible_id_definition_id bigint NOT NULL,
data bytea,
is_deleted boolean NOT NULL,
is_locked boolean NOT NULL,
CONSTRAINT "PK_non_fungible_id_data_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE non_fungible_id_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
non_fungible_resource_entity_id bigint NOT NULL,
non_fungible_id text NOT NULL,
CONSTRAINT "PK_non_fungible_id_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE non_fungible_id_location_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
non_fungible_id_definition_id bigint NOT NULL,
vault_entity_id bigint NOT NULL,
CONSTRAINT "PK_non_fungible_id_location_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE non_fungible_schema_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
resource_entity_id bigint NOT NULL,
schema_defining_entity_id bigint NOT NULL,
schema_hash bytea NOT NULL,
sbor_type_kind sbor_type_kind NOT NULL,
type_index bigint NOT NULL,
CONSTRAINT "PK_non_fungible_schema_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE non_fungible_vault_entry_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
vault_entity_id bigint NOT NULL,
non_fungible_id_definition_id bigint NOT NULL,
CONSTRAINT "PK_non_fungible_vault_entry_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE non_fungible_vault_entry_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
non_fungible_vault_entry_definition_id bigint NOT NULL,
is_deleted boolean NOT NULL,
CONSTRAINT "PK_non_fungible_vault_entry_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE package_blueprint_aggregate_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
package_entity_id bigint NOT NULL,
package_blueprint_ids bigint[] NOT NULL,
CONSTRAINT "PK_package_blueprint_aggregate_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE package_blueprint_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
package_entity_id bigint NOT NULL,
name text NOT NULL,
version text NOT NULL,
definition jsonb NOT NULL,
dependant_entity_ids bigint[],
auth_template jsonb,
auth_template_is_locked boolean,
royalty_config jsonb,
royalty_config_is_locked boolean,
CONSTRAINT "PK_package_blueprint_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE package_code_aggregate_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
package_entity_id bigint NOT NULL,
package_code_ids bigint[] NOT NULL,
CONSTRAINT "PK_package_code_aggregate_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE package_code_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
package_entity_id bigint NOT NULL,
code_hash bytea NOT NULL,
code bytea NOT NULL,
vm_type package_vm_type NOT NULL,
is_deleted boolean NOT NULL,
CONSTRAINT "PK_package_code_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE pending_transactions (
id bigint GENERATED BY DEFAULT AS IDENTITY,
payload_hash text NOT NULL,
intent_hash text NOT NULL,
end_epoch_exclusive bigint NOT NULL,
payload_id bigint,
payload_status pending_transaction_payload_ledger_status NOT NULL,
intent_status pending_transaction_intent_ledger_status NOT NULL,
initial_rejection_reason text,
latest_rejection_reason text,
latest_rejection_timestamp timestamp with time zone,
commit_timestamp timestamp with time zone,
resubmit_from_timestamp timestamp with time zone,
handling_status_reason text,
first_submitted_to_gateway_timestamp timestamp with time zone NOT NULL,
node_submission_count integer NOT NULL,
latest_node_submission_timestamp timestamp with time zone,
latest_submitted_to_node_name text,
latest_node_submission_was_accepted boolean NOT NULL,
last_submit_error text,
CONSTRAINT "PK_pending_transactions" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE resource_entity_supply_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
resource_entity_id bigint NOT NULL,
total_supply numeric(1000) NOT NULL,
total_minted numeric(1000) NOT NULL,
total_burned numeric(1000) NOT NULL,
CONSTRAINT "PK_resource_entity_supply_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE resource_holders (
id bigint GENERATED BY DEFAULT AS IDENTITY,
entity_id bigint NOT NULL,
resource_entity_id bigint NOT NULL,
balance numeric(1000) NOT NULL,
last_updated_at_state_version bigint NOT NULL,
CONSTRAINT "PK_resource_holders" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE schema_entry_aggregate_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
entry_ids bigint[] NOT NULL,
CONSTRAINT "PK_schema_entry_aggregate_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE schema_entry_definition (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
schema_hash bytea NOT NULL,
schema bytea NOT NULL,
CONSTRAINT "PK_schema_entry_definition" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE state_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
discriminator state_type NOT NULL,
json_state jsonb,
sbor_state bytea,
schema_hash bytea,
sbor_type_kind sbor_type_kind,
type_index bigint,
schema_defining_entity_id bigint,
CONSTRAINT "PK_state_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE unverified_standard_metadata_aggregate_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
entry_ids bigint[] NOT NULL,
CONSTRAINT "PK_unverified_standard_metadata_aggregate_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE unverified_standard_metadata_entry_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
entity_id bigint NOT NULL,
is_deleted boolean NOT NULL,
is_locked boolean NOT NULL,
discriminator standard_metadata_key NOT NULL,
entity_ids bigint[],
values text[],
CONSTRAINT "PK_unverified_standard_metadata_entry_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE validator_cumulative_emission_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
validator_entity_id bigint NOT NULL,
epoch_number bigint NOT NULL,
proposals_made bigint NOT NULL,
proposals_missed bigint NOT NULL,
participation_in_active_set bigint NOT NULL,
CONSTRAINT "PK_validator_cumulative_emission_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE validator_public_key_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
validator_entity_id bigint NOT NULL,
key_type public_key_type NOT NULL,
key bytea NOT NULL,
CONSTRAINT "PK_validator_public_key_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE vault_balance_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
vault_entity_id bigint NOT NULL,
balance numeric(1000) NOT NULL,
CONSTRAINT "PK_vault_balance_history" PRIMARY KEY (id)
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE pending_transaction_payloads (
id bigint GENERATED BY DEFAULT AS IDENTITY,
pending_transaction_id bigint,
notarized_transaction_blob bytea NOT NULL,
CONSTRAINT "PK_pending_transaction_payloads" PRIMARY KEY (id),
CONSTRAINT "FK_pending_transaction_payloads_pending_transactions_pending_t~" FOREIGN KEY (pending_transaction_id) REFERENCES pending_transactions (id) ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE TABLE validator_active_set_history (
id bigint GENERATED BY DEFAULT AS IDENTITY,
from_state_version bigint NOT NULL,
epoch bigint NOT NULL,
validator_public_key_history_id bigint NOT NULL,
stake numeric(1000) NOT NULL,
CONSTRAINT "PK_validator_active_set_history" PRIMARY KEY (id),
CONSTRAINT "FK_validator_active_set_history_validator_public_key_history_v~" FOREIGN KEY (validator_public_key_history_id) REFERENCES validator_public_key_history (id) ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_authorized_depositor_aggregate_history_account_enti~" ON account_authorized_depositor_aggregate_history (account_entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_authorized_depositor_entry_history_account_entity_~1" ON account_authorized_depositor_entry_history (account_entity_id, resource_entity_id, non_fungible_id, from_state_version) WHERE discriminator = 'non_fungible';
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_authorized_depositor_entry_history_account_entity_~2" ON account_authorized_depositor_entry_history (account_entity_id, resource_entity_id, from_state_version) WHERE discriminator = 'resource';
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_authorized_depositor_entry_history_account_entity_i~" ON account_authorized_depositor_entry_history (account_entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_default_deposit_rule_history_account_entity_id_from~" ON account_default_deposit_rule_history (account_entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE UNIQUE INDEX "IX_account_locker_entry_definition_account_locker_entity_id_ac~" ON account_locker_entry_definition (account_locker_entity_id, account_entity_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_locker_entry_resource_vault_definition_account_lock~" ON account_locker_entry_resource_vault_definition (account_locker_definition_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_locker_entry_touch_history_account_locker_definitio~" ON account_locker_entry_touch_history (account_locker_definition_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_resource_preference_rule_aggregate_history_account_~" ON account_resource_preference_rule_aggregate_history (account_entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_account_resource_preference_rule_entry_history_account_enti~" ON account_resource_preference_rule_entry_history (account_entity_id, resource_entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_component_method_royalty_aggregate_history_entity_id_from_s~" ON component_method_royalty_aggregate_history (entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_component_method_royalty_entry_history_entity_id_from_state~" ON component_method_royalty_entry_history (entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_component_method_royalty_entry_history_entity_id_method_nam~" ON component_method_royalty_entry_history (entity_id, method_name, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE UNIQUE INDEX "IX_entities_address" ON entities (address);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_entities_from_state_version" ON entities (from_state_version) WHERE discriminator = 'global_validator';
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_entity_metadata_entry_definition_entity_id_from_state_versi~" ON entity_metadata_entry_definition (entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_entity_metadata_entry_definition_entity_id_key" ON entity_metadata_entry_definition (entity_id, key);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_entity_metadata_entry_history_entity_metadata_entry_definit~" ON entity_metadata_entry_history (entity_metadata_entry_definition_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_entity_metadata_totals_history_entity_id_from_state_version" ON entity_metadata_totals_history (entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_entity_resource_balance_history_entity_id_resource_entity_i~" ON entity_resource_balance_history (entity_id, resource_entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_entity_resource_entry_definition_entity_id_from_state_versi~" ON entity_resource_entry_definition (entity_id, from_state_version);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20241016083503_InitialCreate') THEN
CREATE INDEX "IX_entity_resource_entry_definition_fungibles" ON entity_resource_entry_definition (entity_id, from_state_version) WHERE resource_type = 'fungible';
END IF;
END $EF$;