From 60ab3ad53a547b60ac2e65ff88e105184e4b7594 Mon Sep 17 00:00:00 2001 From: Maksim Strebkov <257byte@gmail.com> Date: Sun, 19 May 2024 01:17:48 +0300 Subject: [PATCH] Improve indexes, close #151 --- .../20240424125408_Initial.Designer.cs | 249 +++++------- .../Migrations/20240424125408_Initial.cs | 370 +++++++----------- .../20240501115741_Triggers.Designer.cs | 249 +++++------- .../20240501115809_TokensValue.Designer.cs | 249 +++++------- .../Migrations/TzktContextModelSnapshot.cs | 249 +++++------- Tzkt.Data/Models/Accounts/Account.cs | 4 - Tzkt.Data/Models/Accounts/Commitment.cs | 5 +- Tzkt.Data/Models/Accounts/Contract.cs | 8 +- Tzkt.Data/Models/Accounts/Delegate.cs | 8 +- Tzkt.Data/Models/Baking/BakingRight.cs | 3 - Tzkt.Data/Models/Baking/Cycle.cs | 3 - Tzkt.Data/Models/Baking/SnapshotBalance.cs | 5 +- Tzkt.Data/Models/Baking/StakingUpdate.cs | 14 +- Tzkt.Data/Models/Baking/UnstakeRequest.cs | 2 +- Tzkt.Data/Models/Blocks/Block.cs | 3 - Tzkt.Data/Models/Blocks/Protocol.cs | 13 +- .../Models/Operations/DelegationOperation.cs | 2 +- .../Operations/NonceRevelationOperation.cs | 3 - .../Operations/RegisterConstantOperation.cs | 9 +- .../SetDelegateParametersOperation.cs | 5 +- .../Operations/SetDepositsLimitOperation.cs | 10 +- .../Operations/SmartRollupCementOperation.cs | 8 +- .../Operations/SmartRollupExecuteOperation.cs | 2 +- .../Operations/SmartRollupPublishOperation.cs | 4 +- .../Operations/SmartRollupRefuteOperation.cs | 2 +- .../Models/Operations/TransactionOperation.cs | 8 + .../Operations/VdfRevelationOperation.cs | 2 +- Tzkt.Data/Models/Scripts/BigMap.cs | 7 - Tzkt.Data/Models/Scripts/BigMapKey.cs | 10 +- Tzkt.Data/Models/Scripts/BigMapUpdate.cs | 16 +- Tzkt.Data/Models/Scripts/ContractEvent.cs | 10 - Tzkt.Data/Models/Scripts/Script.cs | 6 +- Tzkt.Data/Models/Scripts/Storage.cs | 8 +- Tzkt.Data/Models/Scripts/Ticket.cs | 7 - Tzkt.Data/Models/Scripts/TicketBalance.cs | 7 - Tzkt.Data/Models/Scripts/TicketTransfer.cs | 12 +- Tzkt.Data/Models/Scripts/Token.cs | 9 +- Tzkt.Data/Models/Scripts/TokenBalance.cs | 15 +- Tzkt.Data/Models/Scripts/TokenTransfer.cs | 18 +- .../Models/SmartRollups/RefutationGame.cs | 2 +- .../SmartRollups/SmartRollupCommitment.cs | 3 - Tzkt.Data/Models/Statistics/Statistics.cs | 4 +- Tzkt.Data/Models/Voting/Proposal.cs | 10 + Tzkt.Data/Models/Voting/VotingPeriod.cs | 7 - Tzkt.Data/Models/Voting/VotingSnapshot.cs | 3 - .../Commits/Operations/DelegationsCommit.cs | 44 +-- .../Operations/SmartRollupRefuteCommit.cs | 2 +- .../Proto18/Commits/SnapshotBalanceCommit.cs | 1 + 48 files changed, 711 insertions(+), 979 deletions(-) diff --git a/Tzkt.Data/Migrations/20240424125408_Initial.Designer.cs b/Tzkt.Data/Migrations/20240424125408_Initial.Designer.cs index 6e4c4248c..701b200dd 100644 --- a/Tzkt.Data/Migrations/20240424125408_Initial.Designer.cs +++ b/Tzkt.Data/Migrations/20240424125408_Initial.Designer.cs @@ -195,9 +195,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FirstLevel"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Metadata"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Metadata"), "gin"); @@ -892,8 +889,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Cycle"); - b.HasIndex("Level"); b.HasIndex("Cycle", "BakerId"); @@ -1002,13 +997,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Ptr"); - b.HasIndex("ContractId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Ptr") .IsUnique(); @@ -1040,7 +1030,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("KeyHash") .HasMaxLength(54) - .HasColumnType("character varying(54)"); + .HasColumnType("character(54)") + .IsFixedLength(); b.Property("LastLevel") .HasColumnType("integer"); @@ -1056,11 +1047,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("BigMapPtr"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonKey"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonKey"), "gin"); @@ -1073,11 +1059,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("LastLevel"); - b.HasIndex("BigMapPtr", "Active") - .HasFilter("\"Active\" = true"); - b.HasIndex("BigMapPtr", "KeyHash"); + b.HasIndex(new[] { "BigMapPtr" }, "IX_BigMapKeys_BigMapPtr_Partial") + .HasFilter("\"Active\" = true"); + b.ToTable("BigMapKeys"); }); @@ -1118,24 +1104,21 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("BigMapKeyId") - .HasFilter("\"BigMapKeyId\" is not null"); - - b.HasIndex("BigMapPtr"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Level"); b.HasIndex("MigrationId") - .HasFilter("\"MigrationId\" is not null"); + .HasFilter("\"MigrationId\" IS NOT NULL"); b.HasIndex("OriginationId") - .HasFilter("\"OriginationId\" is not null"); + .HasFilter("\"OriginationId\" IS NOT NULL"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); + + b.HasIndex("BigMapKeyId", "Id") + .HasFilter("\"BigMapKeyId\" IS NOT NULL"); + + b.HasIndex("BigMapPtr", "Id"); b.ToTable("BigMapUpdates"); }); @@ -1291,10 +1274,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Address") - .IsUnique(); + b.HasIndex("AccountId"); - b.HasIndex("Id") + b.HasIndex("Address") .IsUnique(); b.ToTable("Commitments"); @@ -1334,13 +1316,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractCodeHash"); - - b.HasIndex("ContractId"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonPayload"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonPayload"), "gin"); @@ -1411,8 +1386,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Index"); - b.HasIndex("Index") .IsUnique(); @@ -1581,7 +1554,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SenderCodeHash") .HasFilter("\"SenderCodeHash\" IS NOT NULL"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("DelegationOps"); }); @@ -2001,6 +1974,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("Index") + .HasColumnType("integer"); + b.Property("Level") .HasColumnType("integer"); @@ -2010,9 +1986,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Payload") .HasColumnType("bytea"); - b.Property("Index") - .HasColumnType("integer"); - b.Property("PredecessorLevel") .HasColumnType("integer"); @@ -2208,8 +2181,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("RevealedLevel"); - b.HasIndex("BakerId"); b.HasIndex("Level"); @@ -2425,8 +2396,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("Epoch"); + b.HasIndex("FirstPeriod"); + b.HasIndex("Hash"); + b.HasIndex("LastPeriod"); + + b.HasIndex(new[] { "Status" }, "IX_Proposals_Status_Partial") + .HasFilter("\"Status\" = 0"); + b.ToTable("Proposals"); }); @@ -2654,6 +2632,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("Code") + .IsUnique(); + + b.HasIndex("Hash") + .IsUnique(); + b.ToTable("Protocols"); }); @@ -2761,7 +2745,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OpponentId"); - b.HasIndex("SmartRollupId"); + b.HasIndex("SmartRollupId", "Id"); b.ToTable("RefutationGames"); }); @@ -2803,7 +2787,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("integer"); b.Property("OpHash") - .HasColumnType("text"); + .IsRequired() + .HasMaxLength(51) + .HasColumnType("character(51)") + .IsFixedLength(); b.Property("Refs") .HasColumnType("integer"); @@ -2832,8 +2819,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("Address") - .IsUnique() - .HasFilter("\"Address\" is not null"); + .HasFilter("\"Address\" IS NOT NULL"); b.HasIndex("Level"); @@ -2983,10 +2969,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("ContractId", "Current") + b.HasIndex(new[] { "ContractId" }, "IX_Scripts_ContractId_Partial") .HasFilter("\"Current\" = true"); b.ToTable("Scripts"); @@ -3056,11 +3039,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("ActivationCycle"); + b.HasIndex("Level"); b.HasIndex("OpHash"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("SetDelegateParametersOps"); }); @@ -3098,7 +3083,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("numeric"); b.Property("OpHash") - .HasColumnType("text"); + .IsRequired() + .HasMaxLength(51) + .HasColumnType("character(51)") + .IsFixedLength(); b.Property("SenderId") .HasColumnType("integer"); @@ -3124,7 +3112,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OpHash"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("SetDepositsLimitOps"); }); @@ -3257,12 +3245,16 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("CommitmentId"); + b.HasIndex("Level"); b.HasIndex("OpHash"); b.HasIndex("SenderId"); + b.HasIndex("SmartRollupId", "Id"); + b.ToTable("SmartRollupCementOps"); }); @@ -3315,8 +3307,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Hash"); - b.HasIndex("InboxLevel"); b.HasIndex("LastLevel"); @@ -3397,8 +3387,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("CommitmentId"); - b.HasIndex("Level"); b.HasIndex("OpHash"); @@ -3407,6 +3395,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SmartRollupId"); + b.HasIndex("CommitmentId", "Id"); + b.ToTable("SmartRollupExecuteOps"); }); @@ -3569,11 +3559,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SenderId"); - b.HasIndex("SmartRollupId"); - b.HasIndex("SmartRollupId", "BondStatus", "SenderId") .HasFilter("\"BondStatus\" IS NOT NULL"); + b.HasIndex("SmartRollupId", "SenderId", "Id"); + b.ToTable("SmartRollupPublishOps"); }); @@ -3730,8 +3720,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("GameId"); - b.HasIndex("Level"); b.HasIndex("OpHash"); @@ -3740,6 +3728,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SmartRollupId"); + b.HasIndex("GameId", "Id"); + b.ToTable("SmartRollupRefuteOps"); }); @@ -3780,11 +3770,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Level"); - b.HasIndex("Level", "AccountId", "BakerId"); - b.HasIndex(new[] { "Level" }, "IX_SnapshotBalance_Level_Partial") + b.HasIndex(new[] { "Level" }, "IX_SnapshotBalances_Level_Partial") .HasFilter("\"AccountId\" = \"BakerId\""); b.ToTable("SnapshotBalances"); @@ -3955,24 +3943,24 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("AutostakingOpId") - .HasFilter("\"AutostakingOpId\" is not null"); + .HasFilter("\"AutostakingOpId\" IS NOT NULL"); b.HasIndex("DelegationOpId") - .HasFilter("\"DelegationOpId\" is not null"); + .HasFilter("\"DelegationOpId\" IS NOT NULL"); b.HasIndex("DoubleBakingOpId") - .HasFilter("\"DoubleBakingOpId\" is not null"); + .HasFilter("\"DoubleBakingOpId\" IS NOT NULL"); b.HasIndex("DoubleEndorsingOpId") - .HasFilter("\"DoubleEndorsingOpId\" is not null"); + .HasFilter("\"DoubleEndorsingOpId\" IS NOT NULL"); b.HasIndex("DoublePreendorsingOpId") - .HasFilter("\"DoublePreendorsingOpId\" is not null"); - - b.HasIndex("Level"); + .HasFilter("\"DoublePreendorsingOpId\" IS NOT NULL"); b.HasIndex("StakingOpId") - .HasFilter("\"StakingOpId\" is not null"); + .HasFilter("\"StakingOpId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.HasIndex("BakerId", "Cycle", "Id"); @@ -4078,14 +4066,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractId"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Level"); - b.HasIndex("ContractId", "Current") + b.HasIndex("ContractId", "Id"); + + b.HasIndex(new[] { "ContractId" }, "IX_Storages_ContractId_Partial") .HasFilter("\"Current\" = true"); b.ToTable("Storages"); @@ -4152,9 +4137,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FirstMinterId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonContent"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonContent"), "gin"); @@ -4162,8 +4144,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("LastLevel"); - b.HasIndex("TicketerId"); - b.HasIndex("TypeHash"); b.HasIndex("TicketerId", "TypeHash", "ContentHash"); @@ -4202,13 +4182,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AccountId"); - b.HasIndex("FirstLevel"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("LastLevel"); b.HasIndex("TicketId"); @@ -4262,13 +4237,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FromId"); - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("Level"); - b.HasIndex("SmartRollupExecuteId") - .HasFilter("\"SmartRollupExecuteId\" is not null"); + .HasFilter("\"SmartRollupExecuteId\" IS NOT NULL"); b.HasIndex("TicketId"); @@ -4277,10 +4247,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("ToId"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); b.HasIndex("TransferTicketId") - .HasFilter("\"TransferTicketId\" is not null"); + .HasFilter("\"TransferTicketId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.ToTable("TicketTransfers"); }); @@ -4340,15 +4312,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractId"); - b.HasIndex("FirstMinterId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("LastLevel"); @@ -4397,28 +4364,29 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AccountId") - .HasFilter("\"Balance\" != '0'"); - - b.HasIndex("ContractId") - .HasFilter("\"Balance\" != '0'"); - - b.HasIndex("Id") - .IsUnique(); + b.HasIndex("ContractId"); b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("LastLevel"); - b.HasIndex("TokenId") - .HasFilter("\"Balance\" != '0'"); + b.HasIndex("TokenId"); b.HasIndex("AccountId", "ContractId"); b.HasIndex("AccountId", "TokenId") .IsUnique(); + b.HasIndex(new[] { "AccountId" }, "IX_TokenBalances_AccountId_Partial") + .HasFilter("\"Balance\" != '0'"); + + b.HasIndex(new[] { "ContractId" }, "IX_TokenBalances_ContractId_Partial") + .HasFilter("\"Balance\" != '0'"); + + b.HasIndex(new[] { "TokenId" }, "IX_TokenBalances_TokenId_Partial") + .HasFilter("\"Balance\" != '0'"); + b.ToTable("TokenBalances"); }); @@ -4465,29 +4433,26 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("ContractId"); b.HasIndex("FromId") - .HasFilter("\"FromId\" is not null"); - - b.HasIndex("Id") - .IsUnique(); + .HasFilter("\"FromId\" IS NOT NULL"); b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); - - b.HasIndex("Level"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("MigrationId") - .HasFilter("\"MigrationId\" is not null"); + .HasFilter("\"MigrationId\" IS NOT NULL"); b.HasIndex("OriginationId") - .HasFilter("\"OriginationId\" is not null"); + .HasFilter("\"OriginationId\" IS NOT NULL"); b.HasIndex("ToId") - .HasFilter("\"ToId\" is not null"); + .HasFilter("\"ToId\" IS NOT NULL"); b.HasIndex("TokenId"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.ToTable("TokenTransfers"); }); @@ -4630,6 +4595,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("TargetId"); + b.HasIndex(new[] { "TargetId" }, "IX_TransactionOps_TargetId_Partial") + .HasFilter("\"Entrypoint\" = 'transfer'\r\nAND \"TokenTransfers\" IS NULL\r\nAND \"Status\" = 1"); + b.ToTable("TransactionOps"); }); @@ -5468,12 +5436,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("BakerId"); - b.HasIndex("Cycle"); - b.HasIndex("Level"); b.HasIndex("OpHash"); + b.HasIndex("Cycle", "Id"); + b.ToTable("VdfRevelationOps"); }); @@ -5556,13 +5524,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Index"); - b.HasIndex("Epoch"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Index") .IsUnique(); @@ -5594,8 +5557,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Period"); - b.HasIndex("Period", "BakerId") .IsUnique(); @@ -5649,9 +5610,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("TypeHash"); - b.HasIndex("WeirdDelegateId"); + b.HasIndex("WeirdDelegateId") + .HasFilter("\"WeirdDelegateId\" IS NOT NULL"); - b.HasIndex("Type", "Kind") + b.HasIndex(new[] { "Kind" }, "IX_Accounts_Kind_Partial") .HasFilter("\"Type\" = 2"); b.HasDiscriminator().HasValue((byte)2); @@ -5857,7 +5819,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SoftwareId"); - b.HasIndex("Type", "Staked") + b.HasIndex(new[] { "DeactivationLevel" }, "IX_Accounts_DeactivationLevel_Partial") + .HasFilter("\"Type\" = 1"); + + b.HasIndex(new[] { "Staked" }, "IX_Accounts_Staked_Partial") .HasFilter("\"Type\" = 1"); b.HasDiscriminator().HasValue((byte)1); diff --git a/Tzkt.Data/Migrations/20240424125408_Initial.cs b/Tzkt.Data/Migrations/20240424125408_Initial.cs index 03ea8222a..472477f1e 100644 --- a/Tzkt.Data/Migrations/20240424125408_Initial.cs +++ b/Tzkt.Data/Migrations/20240424125408_Initial.cs @@ -235,7 +235,7 @@ protected override void Up(MigrationBuilder migrationBuilder) LastLevel = table.Column(type: "integer", nullable: false), Updates = table.Column(type: "integer", nullable: false), Active = table.Column(type: "boolean", nullable: false), - KeyHash = table.Column(type: "character varying(54)", maxLength: 54, nullable: true), + KeyHash = table.Column(type: "character(54)", fixedLength: true, maxLength: 54, nullable: true), RawKey = table.Column(type: "bytea", nullable: true), JsonKey = table.Column(type: "jsonb", nullable: true), RawValue = table.Column(type: "bytea", nullable: true), @@ -268,7 +268,6 @@ protected override void Up(MigrationBuilder migrationBuilder) constraints: table => { table.PrimaryKey("PK_BigMaps", x => x.Id); - table.UniqueConstraint("AK_BigMaps_Ptr", x => x.Ptr); }); migrationBuilder.CreateTable( @@ -331,7 +330,6 @@ protected override void Up(MigrationBuilder migrationBuilder) constraints: table => { table.PrimaryKey("PK_Cycles", x => x.Id); - table.UniqueConstraint("AK_Cycles_Index", x => x.Index); }); migrationBuilder.CreateTable( @@ -912,7 +910,6 @@ protected override void Up(MigrationBuilder migrationBuilder) constraints: table => { table.PrimaryKey("PK_VotingPeriods", x => x.Id); - table.UniqueConstraint("AK_VotingPeriods_Index", x => x.Index); }); migrationBuilder.CreateTable( @@ -1589,7 +1586,6 @@ protected override void Up(MigrationBuilder migrationBuilder) constraints: table => { table.PrimaryKey("PK_NonceRevelationOps", x => x.Id); - table.UniqueConstraint("AK_NonceRevelationOps_RevealedLevel", x => x.RevealedLevel); table.ForeignKey( name: "FK_NonceRevelationOps_Accounts_BakerId", column: x => x.BakerId, @@ -1772,7 +1768,7 @@ protected override void Up(MigrationBuilder migrationBuilder) Extras = table.Column(type: "jsonb", nullable: true), Level = table.Column(type: "integer", nullable: false), Timestamp = table.Column(type: "timestamp with time zone", nullable: false), - OpHash = table.Column(type: "text", nullable: true), + OpHash = table.Column(type: "character(51)", fixedLength: true, maxLength: 51, nullable: false), SenderId = table.Column(type: "integer", nullable: false), Counter = table.Column(type: "integer", nullable: false), BakerFee = table.Column(type: "bigint", nullable: false), @@ -1919,7 +1915,7 @@ protected override void Up(MigrationBuilder migrationBuilder) Limit = table.Column(type: "numeric", nullable: true), Level = table.Column(type: "integer", nullable: false), Timestamp = table.Column(type: "timestamp with time zone", nullable: false), - OpHash = table.Column(type: "text", nullable: true), + OpHash = table.Column(type: "character(51)", fixedLength: true, maxLength: 51, nullable: false), SenderId = table.Column(type: "integer", nullable: false), Counter = table.Column(type: "integer", nullable: false), BakerFee = table.Column(type: "bigint", nullable: false), @@ -2819,6 +2815,12 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Accounts", column: "CreatorId"); + migrationBuilder.CreateIndex( + name: "IX_Accounts_DeactivationLevel_Partial", + table: "Accounts", + column: "DeactivationLevel", + filter: "\"Type\" = 1"); + migrationBuilder.CreateIndex( name: "IX_Accounts_DelegateId", table: "Accounts", @@ -2837,10 +2839,10 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "FirstLevel"); migrationBuilder.CreateIndex( - name: "IX_Accounts_Id", + name: "IX_Accounts_Kind_Partial", table: "Accounts", - column: "Id", - unique: true); + column: "Kind", + filter: "\"Type\" = 2"); migrationBuilder.CreateIndex( name: "IX_Accounts_ManagerId", @@ -2859,6 +2861,12 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Accounts", column: "SoftwareId"); + migrationBuilder.CreateIndex( + name: "IX_Accounts_Staked_Partial", + table: "Accounts", + column: "Staked", + filter: "\"Type\" = 1"); + migrationBuilder.CreateIndex( name: "IX_Accounts_Staked_Type", table: "Accounts", @@ -2870,18 +2878,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Accounts", column: "Type"); - migrationBuilder.CreateIndex( - name: "IX_Accounts_Type_Kind", - table: "Accounts", - columns: new[] { "Type", "Kind" }, - filter: "\"Type\" = 2"); - - migrationBuilder.CreateIndex( - name: "IX_Accounts_Type_Staked", - table: "Accounts", - columns: new[] { "Type", "Staked" }, - filter: "\"Type\" = 1"); - migrationBuilder.CreateIndex( name: "IX_Accounts_TypeHash", table: "Accounts", @@ -2896,7 +2892,8 @@ protected override void Up(MigrationBuilder migrationBuilder) migrationBuilder.CreateIndex( name: "IX_Accounts_WeirdDelegateId", table: "Accounts", - column: "WeirdDelegateId"); + column: "WeirdDelegateId", + filter: "\"WeirdDelegateId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_ActivationOps_AccountId", @@ -2934,11 +2931,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "BakerCycles", columns: new[] { "Cycle", "BakerId" }); - migrationBuilder.CreateIndex( - name: "IX_BakingRights_Cycle", - table: "BakingRights", - column: "Cycle"); - migrationBuilder.CreateIndex( name: "IX_BakingRights_Cycle_BakerId", table: "BakingRights", @@ -2979,27 +2971,16 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "BallotOps", column: "SenderId"); - migrationBuilder.CreateIndex( - name: "IX_BigMapKeys_BigMapPtr", - table: "BigMapKeys", - column: "BigMapPtr"); - - migrationBuilder.CreateIndex( - name: "IX_BigMapKeys_BigMapPtr_Active", - table: "BigMapKeys", - columns: new[] { "BigMapPtr", "Active" }, - filter: "\"Active\" = true"); - migrationBuilder.CreateIndex( name: "IX_BigMapKeys_BigMapPtr_KeyHash", table: "BigMapKeys", columns: new[] { "BigMapPtr", "KeyHash" }); migrationBuilder.CreateIndex( - name: "IX_BigMapKeys_Id", + name: "IX_BigMapKeys_BigMapPtr_Partial", table: "BigMapKeys", - column: "Id", - unique: true); + column: "BigMapPtr", + filter: "\"Active\" = true"); migrationBuilder.CreateIndex( name: "IX_BigMapKeys_JsonKey", @@ -3025,12 +3006,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "BigMaps", column: "ContractId"); - migrationBuilder.CreateIndex( - name: "IX_BigMaps_Id", - table: "BigMaps", - column: "Id", - unique: true); - migrationBuilder.CreateIndex( name: "IX_BigMaps_Ptr", table: "BigMaps", @@ -3038,21 +3013,15 @@ protected override void Up(MigrationBuilder migrationBuilder) unique: true); migrationBuilder.CreateIndex( - name: "IX_BigMapUpdates_BigMapKeyId", - table: "BigMapUpdates", - column: "BigMapKeyId", - filter: "\"BigMapKeyId\" is not null"); - - migrationBuilder.CreateIndex( - name: "IX_BigMapUpdates_BigMapPtr", + name: "IX_BigMapUpdates_BigMapKeyId_Id", table: "BigMapUpdates", - column: "BigMapPtr"); + columns: new[] { "BigMapKeyId", "Id" }, + filter: "\"BigMapKeyId\" IS NOT NULL"); migrationBuilder.CreateIndex( - name: "IX_BigMapUpdates_Id", + name: "IX_BigMapUpdates_BigMapPtr_Id", table: "BigMapUpdates", - column: "Id", - unique: true); + columns: new[] { "BigMapPtr", "Id" }); migrationBuilder.CreateIndex( name: "IX_BigMapUpdates_Level", @@ -3063,19 +3032,19 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "IX_BigMapUpdates_MigrationId", table: "BigMapUpdates", column: "MigrationId", - filter: "\"MigrationId\" is not null"); + filter: "\"MigrationId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_BigMapUpdates_OriginationId", table: "BigMapUpdates", column: "OriginationId", - filter: "\"OriginationId\" is not null"); + filter: "\"OriginationId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_BigMapUpdates_TransactionId", table: "BigMapUpdates", column: "TransactionId", - filter: "\"TransactionId\" is not null"); + filter: "\"TransactionId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Blocks_Hash", @@ -3116,15 +3085,14 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "SoftwareId"); migrationBuilder.CreateIndex( - name: "IX_Commitments_Address", + name: "IX_Commitments_AccountId", table: "Commitments", - column: "Address", - unique: true); + column: "AccountId"); migrationBuilder.CreateIndex( - name: "IX_Commitments_Id", + name: "IX_Commitments_Address", table: "Commitments", - column: "Id", + column: "Address", unique: true); migrationBuilder.CreateIndex( @@ -3180,9 +3148,9 @@ protected override void Up(MigrationBuilder migrationBuilder) filter: "\"SenderCodeHash\" IS NOT NULL"); migrationBuilder.CreateIndex( - name: "IX_DelegationOps_SenderId", + name: "IX_DelegationOps_SenderId_Id", table: "DelegationOps", - column: "SenderId"); + columns: new[] { "SenderId", "Id" }); migrationBuilder.CreateIndex( name: "IX_DelegatorCycles_Cycle_BakerId", @@ -3334,32 +3302,16 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "EndorsingRewardOps", column: "Level"); - migrationBuilder.CreateIndex( - name: "IX_Events_ContractCodeHash", - table: "Events", - column: "ContractCodeHash"); - migrationBuilder.CreateIndex( name: "IX_Events_ContractCodeHash_Tag", table: "Events", columns: new[] { "ContractCodeHash", "Tag" }); - migrationBuilder.CreateIndex( - name: "IX_Events_ContractId", - table: "Events", - column: "ContractId"); - migrationBuilder.CreateIndex( name: "IX_Events_ContractId_Tag", table: "Events", columns: new[] { "ContractId", "Tag" }); - migrationBuilder.CreateIndex( - name: "IX_Events_Id", - table: "Events", - column: "Id", - unique: true); - migrationBuilder.CreateIndex( name: "IX_Events_JsonPayload", table: "Events", @@ -3569,11 +3521,39 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Proposals", column: "Epoch"); + migrationBuilder.CreateIndex( + name: "IX_Proposals_FirstPeriod", + table: "Proposals", + column: "FirstPeriod"); + migrationBuilder.CreateIndex( name: "IX_Proposals_Hash", table: "Proposals", column: "Hash"); + migrationBuilder.CreateIndex( + name: "IX_Proposals_LastPeriod", + table: "Proposals", + column: "LastPeriod"); + + migrationBuilder.CreateIndex( + name: "IX_Proposals_Status_Partial", + table: "Proposals", + column: "Status", + filter: "\"Status\" = 0"); + + migrationBuilder.CreateIndex( + name: "IX_Protocols_Code", + table: "Protocols", + column: "Code", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Protocols_Hash", + table: "Protocols", + column: "Hash", + unique: true); + migrationBuilder.CreateIndex( name: "IX_Quotes_Level", table: "Quotes", @@ -3611,16 +3591,15 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "OpponentId"); migrationBuilder.CreateIndex( - name: "IX_RefutationGames_SmartRollupId", + name: "IX_RefutationGames_SmartRollupId_Id", table: "RefutationGames", - column: "SmartRollupId"); + columns: new[] { "SmartRollupId", "Id" }); migrationBuilder.CreateIndex( name: "IX_RegisterConstantOps_Address", table: "RegisterConstantOps", column: "Address", - unique: true, - filter: "\"Address\" is not null"); + filter: "\"Address\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_RegisterConstantOps_Level", @@ -3663,16 +3642,15 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "Level"); migrationBuilder.CreateIndex( - name: "IX_Scripts_ContractId_Current", + name: "IX_Scripts_ContractId_Partial", table: "Scripts", - columns: new[] { "ContractId", "Current" }, + column: "ContractId", filter: "\"Current\" = true"); migrationBuilder.CreateIndex( - name: "IX_Scripts_Id", - table: "Scripts", - column: "Id", - unique: true); + name: "IX_SetDelegateParametersOps_ActivationCycle", + table: "SetDelegateParametersOps", + column: "ActivationCycle"); migrationBuilder.CreateIndex( name: "IX_SetDelegateParametersOps_Level", @@ -3685,9 +3663,9 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "OpHash"); migrationBuilder.CreateIndex( - name: "IX_SetDelegateParametersOps_SenderId", + name: "IX_SetDelegateParametersOps_SenderId_Id", table: "SetDelegateParametersOps", - column: "SenderId"); + columns: new[] { "SenderId", "Id" }); migrationBuilder.CreateIndex( name: "IX_SetDepositsLimitOps_Level", @@ -3700,9 +3678,9 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "OpHash"); migrationBuilder.CreateIndex( - name: "IX_SetDepositsLimitOps_SenderId", + name: "IX_SetDepositsLimitOps_SenderId_Id", table: "SetDepositsLimitOps", - column: "SenderId"); + columns: new[] { "SenderId", "Id" }); migrationBuilder.CreateIndex( name: "IX_SmartRollupAddMessagesOps_Level", @@ -3719,6 +3697,11 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "SmartRollupAddMessagesOps", column: "SenderId"); + migrationBuilder.CreateIndex( + name: "IX_SmartRollupCementOps_CommitmentId", + table: "SmartRollupCementOps", + column: "CommitmentId"); + migrationBuilder.CreateIndex( name: "IX_SmartRollupCementOps_Level", table: "SmartRollupCementOps", @@ -3735,9 +3718,9 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "SenderId"); migrationBuilder.CreateIndex( - name: "IX_SmartRollupCommitments_Hash", - table: "SmartRollupCommitments", - column: "Hash"); + name: "IX_SmartRollupCementOps_SmartRollupId_Id", + table: "SmartRollupCementOps", + columns: new[] { "SmartRollupId", "Id" }); migrationBuilder.CreateIndex( name: "IX_SmartRollupCommitments_Hash_SmartRollupId", @@ -3765,9 +3748,9 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "SmartRollupId"); migrationBuilder.CreateIndex( - name: "IX_SmartRollupExecuteOps_CommitmentId", + name: "IX_SmartRollupExecuteOps_CommitmentId_Id", table: "SmartRollupExecuteOps", - column: "CommitmentId"); + columns: new[] { "CommitmentId", "Id" }); migrationBuilder.CreateIndex( name: "IX_SmartRollupExecuteOps_Level", @@ -3829,17 +3812,17 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "SmartRollupPublishOps", column: "SenderId"); - migrationBuilder.CreateIndex( - name: "IX_SmartRollupPublishOps_SmartRollupId", - table: "SmartRollupPublishOps", - column: "SmartRollupId"); - migrationBuilder.CreateIndex( name: "IX_SmartRollupPublishOps_SmartRollupId_BondStatus_SenderId", table: "SmartRollupPublishOps", columns: new[] { "SmartRollupId", "BondStatus", "SenderId" }, filter: "\"BondStatus\" IS NOT NULL"); + migrationBuilder.CreateIndex( + name: "IX_SmartRollupPublishOps_SmartRollupId_SenderId_Id", + table: "SmartRollupPublishOps", + columns: new[] { "SmartRollupId", "SenderId", "Id" }); + migrationBuilder.CreateIndex( name: "IX_SmartRollupRecoverBondOps_Level", table: "SmartRollupRecoverBondOps", @@ -3866,9 +3849,9 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "StakerId"); migrationBuilder.CreateIndex( - name: "IX_SmartRollupRefuteOps_GameId", + name: "IX_SmartRollupRefuteOps_GameId_Id", table: "SmartRollupRefuteOps", - column: "GameId"); + columns: new[] { "GameId", "Id" }); migrationBuilder.CreateIndex( name: "IX_SmartRollupRefuteOps_Level", @@ -3891,20 +3874,15 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "SmartRollupId"); migrationBuilder.CreateIndex( - name: "IX_SnapshotBalance_Level_Partial", - table: "SnapshotBalances", - column: "Level", - filter: "\"AccountId\" = \"BakerId\""); - - migrationBuilder.CreateIndex( - name: "IX_SnapshotBalances_Level", + name: "IX_SnapshotBalances_Level_AccountId_BakerId", table: "SnapshotBalances", - column: "Level"); + columns: new[] { "Level", "AccountId", "BakerId" }); migrationBuilder.CreateIndex( - name: "IX_SnapshotBalances_Level_AccountId_BakerId", + name: "IX_SnapshotBalances_Level_Partial", table: "SnapshotBalances", - columns: new[] { "Level", "AccountId", "BakerId" }); + column: "Level", + filter: "\"AccountId\" = \"BakerId\""); migrationBuilder.CreateIndex( name: "IX_StakingOps_BakerId", @@ -3930,7 +3908,7 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "IX_StakingUpdates_AutostakingOpId", table: "StakingUpdates", column: "AutostakingOpId", - filter: "\"AutostakingOpId\" is not null"); + filter: "\"AutostakingOpId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_StakingUpdates_BakerId_Cycle_Id", @@ -3941,30 +3919,30 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "IX_StakingUpdates_DelegationOpId", table: "StakingUpdates", column: "DelegationOpId", - filter: "\"DelegationOpId\" is not null"); + filter: "\"DelegationOpId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_StakingUpdates_DoubleBakingOpId", table: "StakingUpdates", column: "DoubleBakingOpId", - filter: "\"DoubleBakingOpId\" is not null"); + filter: "\"DoubleBakingOpId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_StakingUpdates_DoubleEndorsingOpId", table: "StakingUpdates", column: "DoubleEndorsingOpId", - filter: "\"DoubleEndorsingOpId\" is not null"); + filter: "\"DoubleEndorsingOpId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_StakingUpdates_DoublePreendorsingOpId", table: "StakingUpdates", column: "DoublePreendorsingOpId", - filter: "\"DoublePreendorsingOpId\" is not null"); + filter: "\"DoublePreendorsingOpId\" IS NOT NULL"); migrationBuilder.CreateIndex( - name: "IX_StakingUpdates_Level", + name: "IX_StakingUpdates_Level_Id", table: "StakingUpdates", - column: "Level"); + columns: new[] { "Level", "Id" }); migrationBuilder.CreateIndex( name: "IX_StakingUpdates_StakerId_Cycle_Id", @@ -3975,7 +3953,7 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "IX_StakingUpdates_StakingOpId", table: "StakingUpdates", column: "StakingOpId", - filter: "\"StakingOpId\" is not null"); + filter: "\"StakingOpId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Statistics_Cycle", @@ -3998,32 +3976,21 @@ protected override void Up(MigrationBuilder migrationBuilder) unique: true); migrationBuilder.CreateIndex( - name: "IX_Storages_ContractId", + name: "IX_Storages_ContractId_Id", table: "Storages", - column: "ContractId"); + columns: new[] { "ContractId", "Id" }); migrationBuilder.CreateIndex( - name: "IX_Storages_ContractId_Current", + name: "IX_Storages_ContractId_Partial", table: "Storages", - columns: new[] { "ContractId", "Current" }, + column: "ContractId", filter: "\"Current\" = true"); - migrationBuilder.CreateIndex( - name: "IX_Storages_Id", - table: "Storages", - column: "Id", - unique: true); - migrationBuilder.CreateIndex( name: "IX_Storages_Level", table: "Storages", column: "Level"); - migrationBuilder.CreateIndex( - name: "IX_TicketBalances_AccountId", - table: "TicketBalances", - column: "AccountId"); - migrationBuilder.CreateIndex( name: "IX_TicketBalances_AccountId_TicketerId", table: "TicketBalances", @@ -4040,12 +4007,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "TicketBalances", column: "FirstLevel"); - migrationBuilder.CreateIndex( - name: "IX_TicketBalances_Id", - table: "TicketBalances", - column: "Id", - unique: true); - migrationBuilder.CreateIndex( name: "IX_TicketBalances_LastLevel", table: "TicketBalances", @@ -4076,12 +4037,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Tickets", column: "FirstMinterId"); - migrationBuilder.CreateIndex( - name: "IX_Tickets_Id", - table: "Tickets", - column: "Id", - unique: true); - migrationBuilder.CreateIndex( name: "IX_Tickets_JsonContent", table: "Tickets", @@ -4094,11 +4049,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Tickets", column: "LastLevel"); - migrationBuilder.CreateIndex( - name: "IX_Tickets_TicketerId", - table: "Tickets", - column: "TicketerId"); - migrationBuilder.CreateIndex( name: "IX_Tickets_TicketerId_TypeHash_ContentHash", table: "Tickets", @@ -4115,21 +4065,15 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "FromId"); migrationBuilder.CreateIndex( - name: "IX_TicketTransfers_Id", + name: "IX_TicketTransfers_Level_Id", table: "TicketTransfers", - column: "Id", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_TicketTransfers_Level", - table: "TicketTransfers", - column: "Level"); + columns: new[] { "Level", "Id" }); migrationBuilder.CreateIndex( name: "IX_TicketTransfers_SmartRollupExecuteId", table: "TicketTransfers", column: "SmartRollupExecuteId", - filter: "\"SmartRollupExecuteId\" is not null"); + filter: "\"SmartRollupExecuteId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TicketTransfers_TicketerId", @@ -4150,24 +4094,24 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "IX_TicketTransfers_TransactionId", table: "TicketTransfers", column: "TransactionId", - filter: "\"TransactionId\" is not null"); + filter: "\"TransactionId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TicketTransfers_TransferTicketId", table: "TicketTransfers", column: "TransferTicketId", - filter: "\"TransferTicketId\" is not null"); + filter: "\"TransferTicketId\" IS NOT NULL"); migrationBuilder.CreateIndex( - name: "IX_TokenBalances_AccountId", + name: "IX_TokenBalances_AccountId_ContractId", table: "TokenBalances", - column: "AccountId", - filter: "\"Balance\" != '0'"); + columns: new[] { "AccountId", "ContractId" }); migrationBuilder.CreateIndex( - name: "IX_TokenBalances_AccountId_ContractId", + name: "IX_TokenBalances_AccountId_Partial", table: "TokenBalances", - columns: new[] { "AccountId", "ContractId" }); + column: "AccountId", + filter: "\"Balance\" != '0'"); migrationBuilder.CreateIndex( name: "IX_TokenBalances_AccountId_TokenId", @@ -4178,20 +4122,19 @@ protected override void Up(MigrationBuilder migrationBuilder) migrationBuilder.CreateIndex( name: "IX_TokenBalances_ContractId", table: "TokenBalances", - column: "ContractId", - filter: "\"Balance\" != '0'"); + column: "ContractId"); migrationBuilder.CreateIndex( - name: "IX_TokenBalances_Id", + name: "IX_TokenBalances_ContractId_Partial", table: "TokenBalances", - column: "Id", - unique: true); + column: "ContractId", + filter: "\"Balance\" != '0'"); migrationBuilder.CreateIndex( name: "IX_TokenBalances_IndexedAt", table: "TokenBalances", column: "IndexedAt", - filter: "\"IndexedAt\" is not null"); + filter: "\"IndexedAt\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TokenBalances_LastLevel", @@ -4201,13 +4144,13 @@ protected override void Up(MigrationBuilder migrationBuilder) migrationBuilder.CreateIndex( name: "IX_TokenBalances_TokenId", table: "TokenBalances", - column: "TokenId", - filter: "\"Balance\" != '0'"); + column: "TokenId"); migrationBuilder.CreateIndex( - name: "IX_Tokens_ContractId", - table: "Tokens", - column: "ContractId"); + name: "IX_TokenBalances_TokenId_Partial", + table: "TokenBalances", + column: "TokenId", + filter: "\"Balance\" != '0'"); migrationBuilder.CreateIndex( name: "IX_Tokens_ContractId_TokenId", @@ -4220,17 +4163,11 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Tokens", column: "FirstMinterId"); - migrationBuilder.CreateIndex( - name: "IX_Tokens_Id", - table: "Tokens", - column: "Id", - unique: true); - migrationBuilder.CreateIndex( name: "IX_Tokens_IndexedAt", table: "Tokens", column: "IndexedAt", - filter: "\"IndexedAt\" is not null"); + filter: "\"IndexedAt\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Tokens_LastLevel", @@ -4253,42 +4190,36 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "IX_TokenTransfers_FromId", table: "TokenTransfers", column: "FromId", - filter: "\"FromId\" is not null"); - - migrationBuilder.CreateIndex( - name: "IX_TokenTransfers_Id", - table: "TokenTransfers", - column: "Id", - unique: true); + filter: "\"FromId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TokenTransfers_IndexedAt", table: "TokenTransfers", column: "IndexedAt", - filter: "\"IndexedAt\" is not null"); + filter: "\"IndexedAt\" IS NOT NULL"); migrationBuilder.CreateIndex( - name: "IX_TokenTransfers_Level", + name: "IX_TokenTransfers_Level_Id", table: "TokenTransfers", - column: "Level"); + columns: new[] { "Level", "Id" }); migrationBuilder.CreateIndex( name: "IX_TokenTransfers_MigrationId", table: "TokenTransfers", column: "MigrationId", - filter: "\"MigrationId\" is not null"); + filter: "\"MigrationId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TokenTransfers_OriginationId", table: "TokenTransfers", column: "OriginationId", - filter: "\"OriginationId\" is not null"); + filter: "\"OriginationId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TokenTransfers_ToId", table: "TokenTransfers", column: "ToId", - filter: "\"ToId\" is not null"); + filter: "\"ToId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TokenTransfers_TokenId", @@ -4299,7 +4230,7 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "IX_TokenTransfers_TransactionId", table: "TokenTransfers", column: "TransactionId", - filter: "\"TransactionId\" is not null"); + filter: "\"TransactionId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_TransactionOps_InitiatorId", @@ -4350,6 +4281,12 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "TransactionOps", column: "TargetId"); + migrationBuilder.CreateIndex( + name: "IX_TransactionOps_TargetId_Partial", + table: "TransactionOps", + column: "TargetId", + filter: "\"Entrypoint\" = 'transfer'\r\nAND \"TokenTransfers\" IS NULL\r\nAND \"Status\" = 1"); + migrationBuilder.CreateIndex( name: "IX_TransferTicketOps_Level", table: "TransferTicketOps", @@ -4571,9 +4508,9 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "BakerId"); migrationBuilder.CreateIndex( - name: "IX_VdfRevelationOps_Cycle", + name: "IX_VdfRevelationOps_Cycle_Id", table: "VdfRevelationOps", - column: "Cycle"); + columns: new[] { "Cycle", "Id" }); migrationBuilder.CreateIndex( name: "IX_VdfRevelationOps_Level", @@ -4590,23 +4527,12 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "VotingPeriods", column: "Epoch"); - migrationBuilder.CreateIndex( - name: "IX_VotingPeriods_Id", - table: "VotingPeriods", - column: "Id", - unique: true); - migrationBuilder.CreateIndex( name: "IX_VotingPeriods_Index", table: "VotingPeriods", column: "Index", unique: true); - migrationBuilder.CreateIndex( - name: "IX_VotingSnapshots_Period", - table: "VotingSnapshots", - column: "Period"); - migrationBuilder.CreateIndex( name: "IX_VotingSnapshots_Period_BakerId", table: "VotingSnapshots", diff --git a/Tzkt.Data/Migrations/20240501115741_Triggers.Designer.cs b/Tzkt.Data/Migrations/20240501115741_Triggers.Designer.cs index 0c0a5387e..78a84461c 100644 --- a/Tzkt.Data/Migrations/20240501115741_Triggers.Designer.cs +++ b/Tzkt.Data/Migrations/20240501115741_Triggers.Designer.cs @@ -195,9 +195,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FirstLevel"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Metadata"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Metadata"), "gin"); @@ -892,8 +889,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Cycle"); - b.HasIndex("Level"); b.HasIndex("Cycle", "BakerId"); @@ -1002,13 +997,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Ptr"); - b.HasIndex("ContractId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Ptr") .IsUnique(); @@ -1040,7 +1030,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("KeyHash") .HasMaxLength(54) - .HasColumnType("character varying(54)"); + .HasColumnType("character(54)") + .IsFixedLength(); b.Property("LastLevel") .HasColumnType("integer"); @@ -1056,11 +1047,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("BigMapPtr"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonKey"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonKey"), "gin"); @@ -1073,11 +1059,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("LastLevel"); - b.HasIndex("BigMapPtr", "Active") - .HasFilter("\"Active\" = true"); - b.HasIndex("BigMapPtr", "KeyHash"); + b.HasIndex(new[] { "BigMapPtr" }, "IX_BigMapKeys_BigMapPtr_Partial") + .HasFilter("\"Active\" = true"); + b.ToTable("BigMapKeys"); }); @@ -1118,24 +1104,21 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("BigMapKeyId") - .HasFilter("\"BigMapKeyId\" is not null"); - - b.HasIndex("BigMapPtr"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Level"); b.HasIndex("MigrationId") - .HasFilter("\"MigrationId\" is not null"); + .HasFilter("\"MigrationId\" IS NOT NULL"); b.HasIndex("OriginationId") - .HasFilter("\"OriginationId\" is not null"); + .HasFilter("\"OriginationId\" IS NOT NULL"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); + + b.HasIndex("BigMapKeyId", "Id") + .HasFilter("\"BigMapKeyId\" IS NOT NULL"); + + b.HasIndex("BigMapPtr", "Id"); b.ToTable("BigMapUpdates"); }); @@ -1291,10 +1274,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Address") - .IsUnique(); + b.HasIndex("AccountId"); - b.HasIndex("Id") + b.HasIndex("Address") .IsUnique(); b.ToTable("Commitments"); @@ -1334,13 +1316,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractCodeHash"); - - b.HasIndex("ContractId"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonPayload"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonPayload"), "gin"); @@ -1411,8 +1386,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Index"); - b.HasIndex("Index") .IsUnique(); @@ -1581,7 +1554,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SenderCodeHash") .HasFilter("\"SenderCodeHash\" IS NOT NULL"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("DelegationOps"); }); @@ -2001,6 +1974,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("Index") + .HasColumnType("integer"); + b.Property("Level") .HasColumnType("integer"); @@ -2010,9 +1986,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Payload") .HasColumnType("bytea"); - b.Property("Index") - .HasColumnType("integer"); - b.Property("PredecessorLevel") .HasColumnType("integer"); @@ -2208,8 +2181,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("RevealedLevel"); - b.HasIndex("BakerId"); b.HasIndex("Level"); @@ -2425,8 +2396,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("Epoch"); + b.HasIndex("FirstPeriod"); + b.HasIndex("Hash"); + b.HasIndex("LastPeriod"); + + b.HasIndex(new[] { "Status" }, "IX_Proposals_Status_Partial") + .HasFilter("\"Status\" = 0"); + b.ToTable("Proposals"); }); @@ -2654,6 +2632,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("Code") + .IsUnique(); + + b.HasIndex("Hash") + .IsUnique(); + b.ToTable("Protocols"); }); @@ -2761,7 +2745,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OpponentId"); - b.HasIndex("SmartRollupId"); + b.HasIndex("SmartRollupId", "Id"); b.ToTable("RefutationGames"); }); @@ -2803,7 +2787,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("integer"); b.Property("OpHash") - .HasColumnType("text"); + .IsRequired() + .HasMaxLength(51) + .HasColumnType("character(51)") + .IsFixedLength(); b.Property("Refs") .HasColumnType("integer"); @@ -2832,8 +2819,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("Address") - .IsUnique() - .HasFilter("\"Address\" is not null"); + .HasFilter("\"Address\" IS NOT NULL"); b.HasIndex("Level"); @@ -2983,10 +2969,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("ContractId", "Current") + b.HasIndex(new[] { "ContractId" }, "IX_Scripts_ContractId_Partial") .HasFilter("\"Current\" = true"); b.ToTable("Scripts"); @@ -3056,11 +3039,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("ActivationCycle"); + b.HasIndex("Level"); b.HasIndex("OpHash"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("SetDelegateParametersOps"); }); @@ -3098,7 +3083,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("numeric"); b.Property("OpHash") - .HasColumnType("text"); + .IsRequired() + .HasMaxLength(51) + .HasColumnType("character(51)") + .IsFixedLength(); b.Property("SenderId") .HasColumnType("integer"); @@ -3124,7 +3112,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OpHash"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("SetDepositsLimitOps"); }); @@ -3257,12 +3245,16 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("CommitmentId"); + b.HasIndex("Level"); b.HasIndex("OpHash"); b.HasIndex("SenderId"); + b.HasIndex("SmartRollupId", "Id"); + b.ToTable("SmartRollupCementOps"); }); @@ -3315,8 +3307,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Hash"); - b.HasIndex("InboxLevel"); b.HasIndex("LastLevel"); @@ -3397,8 +3387,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("CommitmentId"); - b.HasIndex("Level"); b.HasIndex("OpHash"); @@ -3407,6 +3395,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SmartRollupId"); + b.HasIndex("CommitmentId", "Id"); + b.ToTable("SmartRollupExecuteOps"); }); @@ -3569,11 +3559,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SenderId"); - b.HasIndex("SmartRollupId"); - b.HasIndex("SmartRollupId", "BondStatus", "SenderId") .HasFilter("\"BondStatus\" IS NOT NULL"); + b.HasIndex("SmartRollupId", "SenderId", "Id"); + b.ToTable("SmartRollupPublishOps"); }); @@ -3730,8 +3720,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("GameId"); - b.HasIndex("Level"); b.HasIndex("OpHash"); @@ -3740,6 +3728,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SmartRollupId"); + b.HasIndex("GameId", "Id"); + b.ToTable("SmartRollupRefuteOps"); }); @@ -3780,11 +3770,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Level"); - b.HasIndex("Level", "AccountId", "BakerId"); - b.HasIndex(new[] { "Level" }, "IX_SnapshotBalance_Level_Partial") + b.HasIndex(new[] { "Level" }, "IX_SnapshotBalances_Level_Partial") .HasFilter("\"AccountId\" = \"BakerId\""); b.ToTable("SnapshotBalances"); @@ -3955,24 +3943,24 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("AutostakingOpId") - .HasFilter("\"AutostakingOpId\" is not null"); + .HasFilter("\"AutostakingOpId\" IS NOT NULL"); b.HasIndex("DelegationOpId") - .HasFilter("\"DelegationOpId\" is not null"); + .HasFilter("\"DelegationOpId\" IS NOT NULL"); b.HasIndex("DoubleBakingOpId") - .HasFilter("\"DoubleBakingOpId\" is not null"); + .HasFilter("\"DoubleBakingOpId\" IS NOT NULL"); b.HasIndex("DoubleEndorsingOpId") - .HasFilter("\"DoubleEndorsingOpId\" is not null"); + .HasFilter("\"DoubleEndorsingOpId\" IS NOT NULL"); b.HasIndex("DoublePreendorsingOpId") - .HasFilter("\"DoublePreendorsingOpId\" is not null"); - - b.HasIndex("Level"); + .HasFilter("\"DoublePreendorsingOpId\" IS NOT NULL"); b.HasIndex("StakingOpId") - .HasFilter("\"StakingOpId\" is not null"); + .HasFilter("\"StakingOpId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.HasIndex("BakerId", "Cycle", "Id"); @@ -4078,14 +4066,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractId"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Level"); - b.HasIndex("ContractId", "Current") + b.HasIndex("ContractId", "Id"); + + b.HasIndex(new[] { "ContractId" }, "IX_Storages_ContractId_Partial") .HasFilter("\"Current\" = true"); b.ToTable("Storages"); @@ -4152,9 +4137,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FirstMinterId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonContent"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonContent"), "gin"); @@ -4162,8 +4144,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("LastLevel"); - b.HasIndex("TicketerId"); - b.HasIndex("TypeHash"); b.HasIndex("TicketerId", "TypeHash", "ContentHash"); @@ -4202,13 +4182,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AccountId"); - b.HasIndex("FirstLevel"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("LastLevel"); b.HasIndex("TicketId"); @@ -4262,13 +4237,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FromId"); - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("Level"); - b.HasIndex("SmartRollupExecuteId") - .HasFilter("\"SmartRollupExecuteId\" is not null"); + .HasFilter("\"SmartRollupExecuteId\" IS NOT NULL"); b.HasIndex("TicketId"); @@ -4277,10 +4247,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("ToId"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); b.HasIndex("TransferTicketId") - .HasFilter("\"TransferTicketId\" is not null"); + .HasFilter("\"TransferTicketId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.ToTable("TicketTransfers"); }); @@ -4340,15 +4312,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractId"); - b.HasIndex("FirstMinterId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("LastLevel"); @@ -4397,28 +4364,29 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AccountId") - .HasFilter("\"Balance\" != '0'"); - - b.HasIndex("ContractId") - .HasFilter("\"Balance\" != '0'"); - - b.HasIndex("Id") - .IsUnique(); + b.HasIndex("ContractId"); b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("LastLevel"); - b.HasIndex("TokenId") - .HasFilter("\"Balance\" != '0'"); + b.HasIndex("TokenId"); b.HasIndex("AccountId", "ContractId"); b.HasIndex("AccountId", "TokenId") .IsUnique(); + b.HasIndex(new[] { "AccountId" }, "IX_TokenBalances_AccountId_Partial") + .HasFilter("\"Balance\" != '0'"); + + b.HasIndex(new[] { "ContractId" }, "IX_TokenBalances_ContractId_Partial") + .HasFilter("\"Balance\" != '0'"); + + b.HasIndex(new[] { "TokenId" }, "IX_TokenBalances_TokenId_Partial") + .HasFilter("\"Balance\" != '0'"); + b.ToTable("TokenBalances"); }); @@ -4465,29 +4433,26 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("ContractId"); b.HasIndex("FromId") - .HasFilter("\"FromId\" is not null"); - - b.HasIndex("Id") - .IsUnique(); + .HasFilter("\"FromId\" IS NOT NULL"); b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); - - b.HasIndex("Level"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("MigrationId") - .HasFilter("\"MigrationId\" is not null"); + .HasFilter("\"MigrationId\" IS NOT NULL"); b.HasIndex("OriginationId") - .HasFilter("\"OriginationId\" is not null"); + .HasFilter("\"OriginationId\" IS NOT NULL"); b.HasIndex("ToId") - .HasFilter("\"ToId\" is not null"); + .HasFilter("\"ToId\" IS NOT NULL"); b.HasIndex("TokenId"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.ToTable("TokenTransfers"); }); @@ -4630,6 +4595,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("TargetId"); + b.HasIndex(new[] { "TargetId" }, "IX_TransactionOps_TargetId_Partial") + .HasFilter("\"Entrypoint\" = 'transfer'\r\nAND \"TokenTransfers\" IS NULL\r\nAND \"Status\" = 1"); + b.ToTable("TransactionOps"); }); @@ -5468,12 +5436,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("BakerId"); - b.HasIndex("Cycle"); - b.HasIndex("Level"); b.HasIndex("OpHash"); + b.HasIndex("Cycle", "Id"); + b.ToTable("VdfRevelationOps"); }); @@ -5556,13 +5524,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Index"); - b.HasIndex("Epoch"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Index") .IsUnique(); @@ -5594,8 +5557,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Period"); - b.HasIndex("Period", "BakerId") .IsUnique(); @@ -5649,9 +5610,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("TypeHash"); - b.HasIndex("WeirdDelegateId"); + b.HasIndex("WeirdDelegateId") + .HasFilter("\"WeirdDelegateId\" IS NOT NULL"); - b.HasIndex("Type", "Kind") + b.HasIndex(new[] { "Kind" }, "IX_Accounts_Kind_Partial") .HasFilter("\"Type\" = 2"); b.HasDiscriminator().HasValue((byte)2); @@ -5857,7 +5819,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SoftwareId"); - b.HasIndex("Type", "Staked") + b.HasIndex(new[] { "DeactivationLevel" }, "IX_Accounts_DeactivationLevel_Partial") + .HasFilter("\"Type\" = 1"); + + b.HasIndex(new[] { "Staked" }, "IX_Accounts_Staked_Partial") .HasFilter("\"Type\" = 1"); b.HasDiscriminator().HasValue((byte)1); diff --git a/Tzkt.Data/Migrations/20240501115809_TokensValue.Designer.cs b/Tzkt.Data/Migrations/20240501115809_TokensValue.Designer.cs index 6a77c9b2c..b8b219e45 100644 --- a/Tzkt.Data/Migrations/20240501115809_TokensValue.Designer.cs +++ b/Tzkt.Data/Migrations/20240501115809_TokensValue.Designer.cs @@ -195,9 +195,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FirstLevel"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Metadata"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Metadata"), "gin"); @@ -892,8 +889,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Cycle"); - b.HasIndex("Level"); b.HasIndex("Cycle", "BakerId"); @@ -1002,13 +997,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Ptr"); - b.HasIndex("ContractId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Ptr") .IsUnique(); @@ -1040,7 +1030,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("KeyHash") .HasMaxLength(54) - .HasColumnType("character varying(54)"); + .HasColumnType("character(54)") + .IsFixedLength(); b.Property("LastLevel") .HasColumnType("integer"); @@ -1056,11 +1047,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("BigMapPtr"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonKey"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonKey"), "gin"); @@ -1073,11 +1059,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("LastLevel"); - b.HasIndex("BigMapPtr", "Active") - .HasFilter("\"Active\" = true"); - b.HasIndex("BigMapPtr", "KeyHash"); + b.HasIndex(new[] { "BigMapPtr" }, "IX_BigMapKeys_BigMapPtr_Partial") + .HasFilter("\"Active\" = true"); + b.ToTable("BigMapKeys"); }); @@ -1118,24 +1104,21 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("BigMapKeyId") - .HasFilter("\"BigMapKeyId\" is not null"); - - b.HasIndex("BigMapPtr"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Level"); b.HasIndex("MigrationId") - .HasFilter("\"MigrationId\" is not null"); + .HasFilter("\"MigrationId\" IS NOT NULL"); b.HasIndex("OriginationId") - .HasFilter("\"OriginationId\" is not null"); + .HasFilter("\"OriginationId\" IS NOT NULL"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); + + b.HasIndex("BigMapKeyId", "Id") + .HasFilter("\"BigMapKeyId\" IS NOT NULL"); + + b.HasIndex("BigMapPtr", "Id"); b.ToTable("BigMapUpdates"); }); @@ -1291,10 +1274,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Address") - .IsUnique(); + b.HasIndex("AccountId"); - b.HasIndex("Id") + b.HasIndex("Address") .IsUnique(); b.ToTable("Commitments"); @@ -1334,13 +1316,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractCodeHash"); - - b.HasIndex("ContractId"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonPayload"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonPayload"), "gin"); @@ -1411,8 +1386,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Index"); - b.HasIndex("Index") .IsUnique(); @@ -1581,7 +1554,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SenderCodeHash") .HasFilter("\"SenderCodeHash\" IS NOT NULL"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("DelegationOps"); }); @@ -2001,6 +1974,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("Index") + .HasColumnType("integer"); + b.Property("Level") .HasColumnType("integer"); @@ -2010,9 +1986,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Payload") .HasColumnType("bytea"); - b.Property("Index") - .HasColumnType("integer"); - b.Property("PredecessorLevel") .HasColumnType("integer"); @@ -2208,8 +2181,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("RevealedLevel"); - b.HasIndex("BakerId"); b.HasIndex("Level"); @@ -2425,8 +2396,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("Epoch"); + b.HasIndex("FirstPeriod"); + b.HasIndex("Hash"); + b.HasIndex("LastPeriod"); + + b.HasIndex(new[] { "Status" }, "IX_Proposals_Status_Partial") + .HasFilter("\"Status\" = 0"); + b.ToTable("Proposals"); }); @@ -2654,6 +2632,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("Code") + .IsUnique(); + + b.HasIndex("Hash") + .IsUnique(); + b.ToTable("Protocols"); }); @@ -2761,7 +2745,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OpponentId"); - b.HasIndex("SmartRollupId"); + b.HasIndex("SmartRollupId", "Id"); b.ToTable("RefutationGames"); }); @@ -2803,7 +2787,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("integer"); b.Property("OpHash") - .HasColumnType("text"); + .IsRequired() + .HasMaxLength(51) + .HasColumnType("character(51)") + .IsFixedLength(); b.Property("Refs") .HasColumnType("integer"); @@ -2832,8 +2819,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("Address") - .IsUnique() - .HasFilter("\"Address\" is not null"); + .HasFilter("\"Address\" IS NOT NULL"); b.HasIndex("Level"); @@ -2983,10 +2969,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("ContractId", "Current") + b.HasIndex(new[] { "ContractId" }, "IX_Scripts_ContractId_Partial") .HasFilter("\"Current\" = true"); b.ToTable("Scripts"); @@ -3056,11 +3039,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("ActivationCycle"); + b.HasIndex("Level"); b.HasIndex("OpHash"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("SetDelegateParametersOps"); }); @@ -3098,7 +3083,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasColumnType("numeric"); b.Property("OpHash") - .HasColumnType("text"); + .IsRequired() + .HasMaxLength(51) + .HasColumnType("character(51)") + .IsFixedLength(); b.Property("SenderId") .HasColumnType("integer"); @@ -3124,7 +3112,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OpHash"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("SetDepositsLimitOps"); }); @@ -3257,12 +3245,16 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("CommitmentId"); + b.HasIndex("Level"); b.HasIndex("OpHash"); b.HasIndex("SenderId"); + b.HasIndex("SmartRollupId", "Id"); + b.ToTable("SmartRollupCementOps"); }); @@ -3315,8 +3307,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Hash"); - b.HasIndex("InboxLevel"); b.HasIndex("LastLevel"); @@ -3397,8 +3387,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("CommitmentId"); - b.HasIndex("Level"); b.HasIndex("OpHash"); @@ -3407,6 +3395,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SmartRollupId"); + b.HasIndex("CommitmentId", "Id"); + b.ToTable("SmartRollupExecuteOps"); }); @@ -3569,11 +3559,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SenderId"); - b.HasIndex("SmartRollupId"); - b.HasIndex("SmartRollupId", "BondStatus", "SenderId") .HasFilter("\"BondStatus\" IS NOT NULL"); + b.HasIndex("SmartRollupId", "SenderId", "Id"); + b.ToTable("SmartRollupPublishOps"); }); @@ -3730,8 +3720,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("GameId"); - b.HasIndex("Level"); b.HasIndex("OpHash"); @@ -3740,6 +3728,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SmartRollupId"); + b.HasIndex("GameId", "Id"); + b.ToTable("SmartRollupRefuteOps"); }); @@ -3780,11 +3770,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Level"); - b.HasIndex("Level", "AccountId", "BakerId"); - b.HasIndex(new[] { "Level" }, "IX_SnapshotBalance_Level_Partial") + b.HasIndex(new[] { "Level" }, "IX_SnapshotBalances_Level_Partial") .HasFilter("\"AccountId\" = \"BakerId\""); b.ToTable("SnapshotBalances"); @@ -3955,24 +3943,24 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("AutostakingOpId") - .HasFilter("\"AutostakingOpId\" is not null"); + .HasFilter("\"AutostakingOpId\" IS NOT NULL"); b.HasIndex("DelegationOpId") - .HasFilter("\"DelegationOpId\" is not null"); + .HasFilter("\"DelegationOpId\" IS NOT NULL"); b.HasIndex("DoubleBakingOpId") - .HasFilter("\"DoubleBakingOpId\" is not null"); + .HasFilter("\"DoubleBakingOpId\" IS NOT NULL"); b.HasIndex("DoubleEndorsingOpId") - .HasFilter("\"DoubleEndorsingOpId\" is not null"); + .HasFilter("\"DoubleEndorsingOpId\" IS NOT NULL"); b.HasIndex("DoublePreendorsingOpId") - .HasFilter("\"DoublePreendorsingOpId\" is not null"); - - b.HasIndex("Level"); + .HasFilter("\"DoublePreendorsingOpId\" IS NOT NULL"); b.HasIndex("StakingOpId") - .HasFilter("\"StakingOpId\" is not null"); + .HasFilter("\"StakingOpId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.HasIndex("BakerId", "Cycle", "Id"); @@ -4078,14 +4066,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractId"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Level"); - b.HasIndex("ContractId", "Current") + b.HasIndex("ContractId", "Id"); + + b.HasIndex(new[] { "ContractId" }, "IX_Storages_ContractId_Partial") .HasFilter("\"Current\" = true"); b.ToTable("Storages"); @@ -4152,9 +4137,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FirstMinterId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonContent"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonContent"), "gin"); @@ -4162,8 +4144,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("LastLevel"); - b.HasIndex("TicketerId"); - b.HasIndex("TypeHash"); b.HasIndex("TicketerId", "TypeHash", "ContentHash"); @@ -4202,13 +4182,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AccountId"); - b.HasIndex("FirstLevel"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("LastLevel"); b.HasIndex("TicketId"); @@ -4262,13 +4237,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("FromId"); - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("Level"); - b.HasIndex("SmartRollupExecuteId") - .HasFilter("\"SmartRollupExecuteId\" is not null"); + .HasFilter("\"SmartRollupExecuteId\" IS NOT NULL"); b.HasIndex("TicketId"); @@ -4277,10 +4247,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("ToId"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); b.HasIndex("TransferTicketId") - .HasFilter("\"TransferTicketId\" is not null"); + .HasFilter("\"TransferTicketId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.ToTable("TicketTransfers"); }); @@ -4340,15 +4312,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractId"); - b.HasIndex("FirstMinterId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("LastLevel"); @@ -4397,28 +4364,29 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AccountId") - .HasFilter("\"Balance\" != '0'"); - - b.HasIndex("ContractId") - .HasFilter("\"Balance\" != '0'"); - - b.HasIndex("Id") - .IsUnique(); + b.HasIndex("ContractId"); b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("LastLevel"); - b.HasIndex("TokenId") - .HasFilter("\"Balance\" != '0'"); + b.HasIndex("TokenId"); b.HasIndex("AccountId", "ContractId"); b.HasIndex("AccountId", "TokenId") .IsUnique(); + b.HasIndex(new[] { "AccountId" }, "IX_TokenBalances_AccountId_Partial") + .HasFilter("\"Balance\" != '0'"); + + b.HasIndex(new[] { "ContractId" }, "IX_TokenBalances_ContractId_Partial") + .HasFilter("\"Balance\" != '0'"); + + b.HasIndex(new[] { "TokenId" }, "IX_TokenBalances_TokenId_Partial") + .HasFilter("\"Balance\" != '0'"); + b.ToTable("TokenBalances"); }); @@ -4465,29 +4433,26 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("ContractId"); b.HasIndex("FromId") - .HasFilter("\"FromId\" is not null"); - - b.HasIndex("Id") - .IsUnique(); + .HasFilter("\"FromId\" IS NOT NULL"); b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); - - b.HasIndex("Level"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("MigrationId") - .HasFilter("\"MigrationId\" is not null"); + .HasFilter("\"MigrationId\" IS NOT NULL"); b.HasIndex("OriginationId") - .HasFilter("\"OriginationId\" is not null"); + .HasFilter("\"OriginationId\" IS NOT NULL"); b.HasIndex("ToId") - .HasFilter("\"ToId\" is not null"); + .HasFilter("\"ToId\" IS NOT NULL"); b.HasIndex("TokenId"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.ToTable("TokenTransfers"); }); @@ -4630,6 +4595,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("TargetId"); + b.HasIndex(new[] { "TargetId" }, "IX_TransactionOps_TargetId_Partial") + .HasFilter("\"Entrypoint\" = 'transfer'\r\nAND \"TokenTransfers\" IS NULL\r\nAND \"Status\" = 1"); + b.ToTable("TransactionOps"); }); @@ -5468,12 +5436,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("BakerId"); - b.HasIndex("Cycle"); - b.HasIndex("Level"); b.HasIndex("OpHash"); + b.HasIndex("Cycle", "Id"); + b.ToTable("VdfRevelationOps"); }); @@ -5556,13 +5524,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Index"); - b.HasIndex("Epoch"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Index") .IsUnique(); @@ -5594,8 +5557,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Period"); - b.HasIndex("Period", "BakerId") .IsUnique(); @@ -5649,9 +5610,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("TypeHash"); - b.HasIndex("WeirdDelegateId"); + b.HasIndex("WeirdDelegateId") + .HasFilter("\"WeirdDelegateId\" IS NOT NULL"); - b.HasIndex("Type", "Kind") + b.HasIndex(new[] { "Kind" }, "IX_Accounts_Kind_Partial") .HasFilter("\"Type\" = 2"); b.HasDiscriminator().HasValue((byte)2); @@ -5857,7 +5819,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("SoftwareId"); - b.HasIndex("Type", "Staked") + b.HasIndex(new[] { "DeactivationLevel" }, "IX_Accounts_DeactivationLevel_Partial") + .HasFilter("\"Type\" = 1"); + + b.HasIndex(new[] { "Staked" }, "IX_Accounts_Staked_Partial") .HasFilter("\"Type\" = 1"); b.HasDiscriminator().HasValue((byte)1); diff --git a/Tzkt.Data/Migrations/TzktContextModelSnapshot.cs b/Tzkt.Data/Migrations/TzktContextModelSnapshot.cs index b2e815fa6..72147edc7 100644 --- a/Tzkt.Data/Migrations/TzktContextModelSnapshot.cs +++ b/Tzkt.Data/Migrations/TzktContextModelSnapshot.cs @@ -192,9 +192,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("FirstLevel"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Metadata"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Metadata"), "gin"); @@ -889,8 +886,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Cycle"); - b.HasIndex("Level"); b.HasIndex("Cycle", "BakerId"); @@ -999,13 +994,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Ptr"); - b.HasIndex("ContractId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Ptr") .IsUnique(); @@ -1037,7 +1027,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("KeyHash") .HasMaxLength(54) - .HasColumnType("character varying(54)"); + .HasColumnType("character(54)") + .IsFixedLength(); b.Property("LastLevel") .HasColumnType("integer"); @@ -1053,11 +1044,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("BigMapPtr"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonKey"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonKey"), "gin"); @@ -1070,11 +1056,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("LastLevel"); - b.HasIndex("BigMapPtr", "Active") - .HasFilter("\"Active\" = true"); - b.HasIndex("BigMapPtr", "KeyHash"); + b.HasIndex(new[] { "BigMapPtr" }, "IX_BigMapKeys_BigMapPtr_Partial") + .HasFilter("\"Active\" = true"); + b.ToTable("BigMapKeys"); }); @@ -1115,24 +1101,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("BigMapKeyId") - .HasFilter("\"BigMapKeyId\" is not null"); - - b.HasIndex("BigMapPtr"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Level"); b.HasIndex("MigrationId") - .HasFilter("\"MigrationId\" is not null"); + .HasFilter("\"MigrationId\" IS NOT NULL"); b.HasIndex("OriginationId") - .HasFilter("\"OriginationId\" is not null"); + .HasFilter("\"OriginationId\" IS NOT NULL"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); + + b.HasIndex("BigMapKeyId", "Id") + .HasFilter("\"BigMapKeyId\" IS NOT NULL"); + + b.HasIndex("BigMapPtr", "Id"); b.ToTable("BigMapUpdates"); }); @@ -1288,10 +1271,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Address") - .IsUnique(); + b.HasIndex("AccountId"); - b.HasIndex("Id") + b.HasIndex("Address") .IsUnique(); b.ToTable("Commitments"); @@ -1331,13 +1313,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractCodeHash"); - - b.HasIndex("ContractId"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonPayload"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonPayload"), "gin"); @@ -1408,8 +1383,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Index"); - b.HasIndex("Index") .IsUnique(); @@ -1578,7 +1551,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("SenderCodeHash") .HasFilter("\"SenderCodeHash\" IS NOT NULL"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("DelegationOps"); }); @@ -1998,6 +1971,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("Index") + .HasColumnType("integer"); + b.Property("Level") .HasColumnType("integer"); @@ -2007,9 +1983,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Payload") .HasColumnType("bytea"); - b.Property("Index") - .HasColumnType("integer"); - b.Property("PredecessorLevel") .HasColumnType("integer"); @@ -2205,8 +2178,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("RevealedLevel"); - b.HasIndex("BakerId"); b.HasIndex("Level"); @@ -2422,8 +2393,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("Epoch"); + b.HasIndex("FirstPeriod"); + b.HasIndex("Hash"); + b.HasIndex("LastPeriod"); + + b.HasIndex(new[] { "Status" }, "IX_Proposals_Status_Partial") + .HasFilter("\"Status\" = 0"); + b.ToTable("Proposals"); }); @@ -2651,6 +2629,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("Code") + .IsUnique(); + + b.HasIndex("Hash") + .IsUnique(); + b.ToTable("Protocols"); }); @@ -2758,7 +2742,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("OpponentId"); - b.HasIndex("SmartRollupId"); + b.HasIndex("SmartRollupId", "Id"); b.ToTable("RefutationGames"); }); @@ -2800,7 +2784,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("integer"); b.Property("OpHash") - .HasColumnType("text"); + .IsRequired() + .HasMaxLength(51) + .HasColumnType("character(51)") + .IsFixedLength(); b.Property("Refs") .HasColumnType("integer"); @@ -2829,8 +2816,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("Address") - .IsUnique() - .HasFilter("\"Address\" is not null"); + .HasFilter("\"Address\" IS NOT NULL"); b.HasIndex("Level"); @@ -2980,10 +2966,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("ContractId", "Current") + b.HasIndex(new[] { "ContractId" }, "IX_Scripts_ContractId_Partial") .HasFilter("\"Current\" = true"); b.ToTable("Scripts"); @@ -3053,11 +3036,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("ActivationCycle"); + b.HasIndex("Level"); b.HasIndex("OpHash"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("SetDelegateParametersOps"); }); @@ -3095,7 +3080,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("numeric"); b.Property("OpHash") - .HasColumnType("text"); + .IsRequired() + .HasMaxLength(51) + .HasColumnType("character(51)") + .IsFixedLength(); b.Property("SenderId") .HasColumnType("integer"); @@ -3121,7 +3109,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("OpHash"); - b.HasIndex("SenderId"); + b.HasIndex("SenderId", "Id"); b.ToTable("SetDepositsLimitOps"); }); @@ -3254,12 +3242,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("CommitmentId"); + b.HasIndex("Level"); b.HasIndex("OpHash"); b.HasIndex("SenderId"); + b.HasIndex("SmartRollupId", "Id"); + b.ToTable("SmartRollupCementOps"); }); @@ -3312,8 +3304,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Hash"); - b.HasIndex("InboxLevel"); b.HasIndex("LastLevel"); @@ -3394,8 +3384,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("CommitmentId"); - b.HasIndex("Level"); b.HasIndex("OpHash"); @@ -3404,6 +3392,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("SmartRollupId"); + b.HasIndex("CommitmentId", "Id"); + b.ToTable("SmartRollupExecuteOps"); }); @@ -3566,11 +3556,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("SenderId"); - b.HasIndex("SmartRollupId"); - b.HasIndex("SmartRollupId", "BondStatus", "SenderId") .HasFilter("\"BondStatus\" IS NOT NULL"); + b.HasIndex("SmartRollupId", "SenderId", "Id"); + b.ToTable("SmartRollupPublishOps"); }); @@ -3727,8 +3717,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("GameId"); - b.HasIndex("Level"); b.HasIndex("OpHash"); @@ -3737,6 +3725,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("SmartRollupId"); + b.HasIndex("GameId", "Id"); + b.ToTable("SmartRollupRefuteOps"); }); @@ -3777,11 +3767,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Level"); - b.HasIndex("Level", "AccountId", "BakerId"); - b.HasIndex(new[] { "Level" }, "IX_SnapshotBalance_Level_Partial") + b.HasIndex(new[] { "Level" }, "IX_SnapshotBalances_Level_Partial") .HasFilter("\"AccountId\" = \"BakerId\""); b.ToTable("SnapshotBalances"); @@ -3952,24 +3940,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("AutostakingOpId") - .HasFilter("\"AutostakingOpId\" is not null"); + .HasFilter("\"AutostakingOpId\" IS NOT NULL"); b.HasIndex("DelegationOpId") - .HasFilter("\"DelegationOpId\" is not null"); + .HasFilter("\"DelegationOpId\" IS NOT NULL"); b.HasIndex("DoubleBakingOpId") - .HasFilter("\"DoubleBakingOpId\" is not null"); + .HasFilter("\"DoubleBakingOpId\" IS NOT NULL"); b.HasIndex("DoubleEndorsingOpId") - .HasFilter("\"DoubleEndorsingOpId\" is not null"); + .HasFilter("\"DoubleEndorsingOpId\" IS NOT NULL"); b.HasIndex("DoublePreendorsingOpId") - .HasFilter("\"DoublePreendorsingOpId\" is not null"); - - b.HasIndex("Level"); + .HasFilter("\"DoublePreendorsingOpId\" IS NOT NULL"); b.HasIndex("StakingOpId") - .HasFilter("\"StakingOpId\" is not null"); + .HasFilter("\"StakingOpId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.HasIndex("BakerId", "Cycle", "Id"); @@ -4075,14 +4063,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractId"); - - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Level"); - b.HasIndex("ContractId", "Current") + b.HasIndex("ContractId", "Id"); + + b.HasIndex(new[] { "ContractId" }, "IX_Storages_ContractId_Partial") .HasFilter("\"Current\" = true"); b.ToTable("Storages"); @@ -4149,9 +4134,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("FirstMinterId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("JsonContent"); NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("JsonContent"), "gin"); @@ -4159,8 +4141,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("LastLevel"); - b.HasIndex("TicketerId"); - b.HasIndex("TypeHash"); b.HasIndex("TicketerId", "TypeHash", "ContentHash"); @@ -4199,13 +4179,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AccountId"); - b.HasIndex("FirstLevel"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("LastLevel"); b.HasIndex("TicketId"); @@ -4259,13 +4234,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("FromId"); - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("Level"); - b.HasIndex("SmartRollupExecuteId") - .HasFilter("\"SmartRollupExecuteId\" is not null"); + .HasFilter("\"SmartRollupExecuteId\" IS NOT NULL"); b.HasIndex("TicketId"); @@ -4274,10 +4244,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("ToId"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); b.HasIndex("TransferTicketId") - .HasFilter("\"TransferTicketId\" is not null"); + .HasFilter("\"TransferTicketId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.ToTable("TicketTransfers"); }); @@ -4337,15 +4309,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("ContractId"); - b.HasIndex("FirstMinterId"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("LastLevel"); @@ -4394,28 +4361,29 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AccountId") - .HasFilter("\"Balance\" != '0'"); - - b.HasIndex("ContractId") - .HasFilter("\"Balance\" != '0'"); - - b.HasIndex("Id") - .IsUnique(); + b.HasIndex("ContractId"); b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("LastLevel"); - b.HasIndex("TokenId") - .HasFilter("\"Balance\" != '0'"); + b.HasIndex("TokenId"); b.HasIndex("AccountId", "ContractId"); b.HasIndex("AccountId", "TokenId") .IsUnique(); + b.HasIndex(new[] { "AccountId" }, "IX_TokenBalances_AccountId_Partial") + .HasFilter("\"Balance\" != '0'"); + + b.HasIndex(new[] { "ContractId" }, "IX_TokenBalances_ContractId_Partial") + .HasFilter("\"Balance\" != '0'"); + + b.HasIndex(new[] { "TokenId" }, "IX_TokenBalances_TokenId_Partial") + .HasFilter("\"Balance\" != '0'"); + b.ToTable("TokenBalances"); }); @@ -4462,29 +4430,26 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("ContractId"); b.HasIndex("FromId") - .HasFilter("\"FromId\" is not null"); - - b.HasIndex("Id") - .IsUnique(); + .HasFilter("\"FromId\" IS NOT NULL"); b.HasIndex("IndexedAt") - .HasFilter("\"IndexedAt\" is not null"); - - b.HasIndex("Level"); + .HasFilter("\"IndexedAt\" IS NOT NULL"); b.HasIndex("MigrationId") - .HasFilter("\"MigrationId\" is not null"); + .HasFilter("\"MigrationId\" IS NOT NULL"); b.HasIndex("OriginationId") - .HasFilter("\"OriginationId\" is not null"); + .HasFilter("\"OriginationId\" IS NOT NULL"); b.HasIndex("ToId") - .HasFilter("\"ToId\" is not null"); + .HasFilter("\"ToId\" IS NOT NULL"); b.HasIndex("TokenId"); b.HasIndex("TransactionId") - .HasFilter("\"TransactionId\" is not null"); + .HasFilter("\"TransactionId\" IS NOT NULL"); + + b.HasIndex("Level", "Id"); b.ToTable("TokenTransfers"); }); @@ -4627,6 +4592,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("TargetId"); + b.HasIndex(new[] { "TargetId" }, "IX_TransactionOps_TargetId_Partial") + .HasFilter("\"Entrypoint\" = 'transfer'\r\nAND \"TokenTransfers\" IS NULL\r\nAND \"Status\" = 1"); + b.ToTable("TransactionOps"); }); @@ -5465,12 +5433,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("BakerId"); - b.HasIndex("Cycle"); - b.HasIndex("Level"); b.HasIndex("OpHash"); + b.HasIndex("Cycle", "Id"); + b.ToTable("VdfRevelationOps"); }); @@ -5553,13 +5521,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasAlternateKey("Index"); - b.HasIndex("Epoch"); - b.HasIndex("Id") - .IsUnique(); - b.HasIndex("Index") .IsUnique(); @@ -5591,8 +5554,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("Period"); - b.HasIndex("Period", "BakerId") .IsUnique(); @@ -5646,9 +5607,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("TypeHash"); - b.HasIndex("WeirdDelegateId"); + b.HasIndex("WeirdDelegateId") + .HasFilter("\"WeirdDelegateId\" IS NOT NULL"); - b.HasIndex("Type", "Kind") + b.HasIndex(new[] { "Kind" }, "IX_Accounts_Kind_Partial") .HasFilter("\"Type\" = 2"); b.HasDiscriminator().HasValue((byte)2); @@ -5854,7 +5816,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("SoftwareId"); - b.HasIndex("Type", "Staked") + b.HasIndex(new[] { "DeactivationLevel" }, "IX_Accounts_DeactivationLevel_Partial") + .HasFilter("\"Type\" = 1"); + + b.HasIndex(new[] { "Staked" }, "IX_Accounts_Staked_Partial") .HasFilter("\"Type\" = 1"); b.HasDiscriminator().HasValue((byte)1); diff --git a/Tzkt.Data/Models/Accounts/Account.cs b/Tzkt.Data/Models/Accounts/Account.cs index 7ded57509..11a9b0c47 100644 --- a/Tzkt.Data/Models/Accounts/Account.cs +++ b/Tzkt.Data/Models/Accounts/Account.cs @@ -127,10 +127,6 @@ public static void BuildAccountModel(this ModelBuilder modelBuilder) #endregion #region indexes - modelBuilder.Entity() - .HasIndex(x => x.Id) - .IsUnique(); - modelBuilder.Entity() .HasIndex(x => x.Address) .IsUnique(); diff --git a/Tzkt.Data/Models/Accounts/Commitment.cs b/Tzkt.Data/Models/Accounts/Commitment.cs index d179f4696..4fee68495 100644 --- a/Tzkt.Data/Models/Accounts/Commitment.cs +++ b/Tzkt.Data/Models/Accounts/Commitment.cs @@ -31,12 +31,11 @@ public static void BuildCommitmentModel(this ModelBuilder modelBuilder) #region indexes modelBuilder.Entity() - .HasIndex(x => x.Id) + .HasIndex(x => x.Address) .IsUnique(); modelBuilder.Entity() - .HasIndex(x => x.Address) - .IsUnique(); + .HasIndex(x => x.AccountId); #endregion } } diff --git a/Tzkt.Data/Models/Accounts/Contract.cs b/Tzkt.Data/Models/Accounts/Contract.cs index e838c6fdd..af1a6ee60 100644 --- a/Tzkt.Data/Models/Accounts/Contract.cs +++ b/Tzkt.Data/Models/Accounts/Contract.cs @@ -60,8 +60,8 @@ public static void BuildContractModel(this ModelBuilder modelBuilder) { #region indexes modelBuilder.Entity() - .HasIndex(x => new { x.Type, x.Kind }) - .HasFilter(@"""Type"" = 2"); + .HasIndex(x => x.Kind, $"IX_{nameof(TzktContext.Accounts)}_{nameof(Contract.Kind)}_Partial") + .HasFilter($@"""{nameof(Account.Type)}"" = {(int)AccountType.Contract}"); modelBuilder.Entity() .HasIndex(x => x.CreatorId); @@ -69,6 +69,10 @@ public static void BuildContractModel(this ModelBuilder modelBuilder) modelBuilder.Entity() .HasIndex(x => x.ManagerId); + modelBuilder.Entity() + .HasIndex(x => x.WeirdDelegateId) + .HasFilter($@"""{nameof(Contract.WeirdDelegateId)}"" IS NOT NULL"); + modelBuilder.Entity() .HasIndex(x => x.TypeHash); diff --git a/Tzkt.Data/Models/Accounts/Delegate.cs b/Tzkt.Data/Models/Accounts/Delegate.cs index e7bdc12d1..9591513e7 100644 --- a/Tzkt.Data/Models/Accounts/Delegate.cs +++ b/Tzkt.Data/Models/Accounts/Delegate.cs @@ -58,8 +58,12 @@ public static void BuildDelegateModel(this ModelBuilder modelBuilder) { #region indexes modelBuilder.Entity() - .HasIndex(x => new { x.Type, x.Staked }) - .HasFilter(@"""Type"" = 1"); + .HasIndex(x => x.Staked, $"IX_{nameof(TzktContext.Accounts)}_{nameof(Delegate.Staked)}_Partial") + .HasFilter($@"""{nameof(Account.Type)}"" = {(int)AccountType.Delegate}"); + + modelBuilder.Entity() + .HasIndex(x => x.DeactivationLevel, $"IX_{nameof(TzktContext.Accounts)}_{nameof(Delegate.DeactivationLevel)}_Partial") + .HasFilter($@"""{nameof(Account.Type)}"" = {(int)AccountType.Delegate}"); #endregion #region relations diff --git a/Tzkt.Data/Models/Baking/BakingRight.cs b/Tzkt.Data/Models/Baking/BakingRight.cs index 1447ce237..f6103f2ee 100644 --- a/Tzkt.Data/Models/Baking/BakingRight.cs +++ b/Tzkt.Data/Models/Baking/BakingRight.cs @@ -44,9 +44,6 @@ public static void BuildBakingRightModel(this ModelBuilder modelBuilder) modelBuilder.Entity() .HasIndex(x => x.Level); - modelBuilder.Entity() - .HasIndex(x => x.Cycle); - modelBuilder.Entity() .HasIndex(x => new { x.Cycle, x.BakerId }); #endregion diff --git a/Tzkt.Data/Models/Baking/Cycle.cs b/Tzkt.Data/Models/Baking/Cycle.cs index 0ed4668ff..293657afd 100644 --- a/Tzkt.Data/Models/Baking/Cycle.cs +++ b/Tzkt.Data/Models/Baking/Cycle.cs @@ -31,9 +31,6 @@ public static void BuildCycleModel(this ModelBuilder modelBuilder) #region keys modelBuilder.Entity() .HasKey(x => x.Id); - - modelBuilder.Entity() - .HasAlternateKey(x => x.Index); #endregion #region props diff --git a/Tzkt.Data/Models/Baking/SnapshotBalance.cs b/Tzkt.Data/Models/Baking/SnapshotBalance.cs index 1543920eb..124b48e45 100644 --- a/Tzkt.Data/Models/Baking/SnapshotBalance.cs +++ b/Tzkt.Data/Models/Baking/SnapshotBalance.cs @@ -35,10 +35,7 @@ public static void BuildSnapshotBalanceModel(this ModelBuilder modelBuilder) #region indexes modelBuilder.Entity() - .HasIndex(x => x.Level); - - modelBuilder.Entity() - .HasIndex(x => x.Level, "IX_SnapshotBalance_Level_Partial") + .HasIndex(x => x.Level, $"IX_{nameof(TzktContext.SnapshotBalances)}_{nameof(SnapshotBalance.Level)}_Partial") .HasFilter(@"""AccountId"" = ""BakerId"""); modelBuilder.Entity() diff --git a/Tzkt.Data/Models/Baking/StakingUpdate.cs b/Tzkt.Data/Models/Baking/StakingUpdate.cs index b3799fd05..9989f3dbc 100644 --- a/Tzkt.Data/Models/Baking/StakingUpdate.cs +++ b/Tzkt.Data/Models/Baking/StakingUpdate.cs @@ -45,7 +45,7 @@ public static void BuildStakingUpdateModel(this ModelBuilder modelBuilder) #region indexes modelBuilder.Entity() - .HasIndex(x => x.Level); + .HasIndex(x => new { x.Level, x.Id }); modelBuilder.Entity() .HasIndex(x => new { x.BakerId, x.Cycle, x.Id }); @@ -55,27 +55,27 @@ public static void BuildStakingUpdateModel(this ModelBuilder modelBuilder) modelBuilder.Entity() .HasIndex(x => x.AutostakingOpId) - .HasFilter($@"""{nameof(StakingUpdate.AutostakingOpId)}"" is not null"); + .HasFilter($@"""{nameof(StakingUpdate.AutostakingOpId)}"" IS NOT NULL"); modelBuilder.Entity() .HasIndex(x => x.StakingOpId) - .HasFilter($@"""{nameof(StakingUpdate.StakingOpId)}"" is not null"); + .HasFilter($@"""{nameof(StakingUpdate.StakingOpId)}"" IS NOT NULL"); modelBuilder.Entity() .HasIndex(x => x.DelegationOpId) - .HasFilter($@"""{nameof(StakingUpdate.DelegationOpId)}"" is not null"); + .HasFilter($@"""{nameof(StakingUpdate.DelegationOpId)}"" IS NOT NULL"); modelBuilder.Entity() .HasIndex(x => x.DoubleBakingOpId) - .HasFilter($@"""{nameof(StakingUpdate.DoubleBakingOpId)}"" is not null"); + .HasFilter($@"""{nameof(StakingUpdate.DoubleBakingOpId)}"" IS NOT NULL"); modelBuilder.Entity() .HasIndex(x => x.DoubleEndorsingOpId) - .HasFilter($@"""{nameof(StakingUpdate.DoubleEndorsingOpId)}"" is not null"); + .HasFilter($@"""{nameof(StakingUpdate.DoubleEndorsingOpId)}"" IS NOT NULL"); modelBuilder.Entity() .HasIndex(x => x.DoublePreendorsingOpId) - .HasFilter($@"""{nameof(StakingUpdate.DoublePreendorsingOpId)}"" is not null"); + .HasFilter($@"""{nameof(StakingUpdate.DoublePreendorsingOpId)}"" IS NOT NULL"); #endregion } } diff --git a/Tzkt.Data/Models/Baking/UnstakeRequest.cs b/Tzkt.Data/Models/Baking/UnstakeRequest.cs index a4727a02f..c8f05d661 100644 --- a/Tzkt.Data/Models/Baking/UnstakeRequest.cs +++ b/Tzkt.Data/Models/Baking/UnstakeRequest.cs @@ -26,7 +26,7 @@ public static class UnstakeRequestModel public static void BuildUnstakeRequestModel(this ModelBuilder modelBuilder) { #region keys - modelBuilder.Entity() + modelBuilder.Entity() .HasKey(x => x.Id); #endregion diff --git a/Tzkt.Data/Models/Blocks/Block.cs b/Tzkt.Data/Models/Blocks/Block.cs index fbfa4b101..6619d38bf 100644 --- a/Tzkt.Data/Models/Blocks/Block.cs +++ b/Tzkt.Data/Models/Blocks/Block.cs @@ -120,9 +120,6 @@ public static void BuildBlockModel(this ModelBuilder modelBuilder) #region keys modelBuilder.Entity() .HasKey(x => x.Id); - - modelBuilder.Entity() - .HasAlternateKey(x => x.Level); #endregion #region props diff --git a/Tzkt.Data/Models/Blocks/Protocol.cs b/Tzkt.Data/Models/Blocks/Protocol.cs index 50c7f325f..96d18c4df 100644 --- a/Tzkt.Data/Models/Blocks/Protocol.cs +++ b/Tzkt.Data/Models/Blocks/Protocol.cs @@ -133,9 +133,6 @@ public static void BuildProtocolModel(this ModelBuilder modelBuilder) #region keys modelBuilder.Entity() .HasKey(x => x.Id); - - modelBuilder.Entity() - .HasAlternateKey(x => x.Code); #endregion #region props @@ -150,6 +147,16 @@ public static void BuildProtocolModel(this ModelBuilder modelBuilder) .Property("Extras") .HasColumnType("jsonb"); #endregion + + #region indexes + modelBuilder.Entity() + .HasIndex(x => x.Code) + .IsUnique(); + + modelBuilder.Entity() + .HasIndex(x => x.Hash) + .IsUnique(); + #endregion } } } diff --git a/Tzkt.Data/Models/Operations/DelegationOperation.cs b/Tzkt.Data/Models/Operations/DelegationOperation.cs index f8ff37d5e..719287d41 100644 --- a/Tzkt.Data/Models/Operations/DelegationOperation.cs +++ b/Tzkt.Data/Models/Operations/DelegationOperation.cs @@ -49,7 +49,7 @@ public static void BuildDelegationOperationModel(this ModelBuilder modelBuilder) .HasIndex(x => x.OpHash); modelBuilder.Entity() - .HasIndex(x => x.SenderId); + .HasIndex(x => new { x.SenderId, x.Id }); modelBuilder.Entity() .HasIndex(x => x.SenderCodeHash) diff --git a/Tzkt.Data/Models/Operations/NonceRevelationOperation.cs b/Tzkt.Data/Models/Operations/NonceRevelationOperation.cs index 36df8a0bd..76a735084 100644 --- a/Tzkt.Data/Models/Operations/NonceRevelationOperation.cs +++ b/Tzkt.Data/Models/Operations/NonceRevelationOperation.cs @@ -36,9 +36,6 @@ public static void BuildNonceRevelationOperationModel(this ModelBuilder modelBui #region keys modelBuilder.Entity() .HasKey(x => x.Id); - - modelBuilder.Entity() - .HasAlternateKey(x => x.RevealedLevel); #endregion #region props diff --git a/Tzkt.Data/Models/Operations/RegisterConstantOperation.cs b/Tzkt.Data/Models/Operations/RegisterConstantOperation.cs index 3af192129..dadae2264 100644 --- a/Tzkt.Data/Models/Operations/RegisterConstantOperation.cs +++ b/Tzkt.Data/Models/Operations/RegisterConstantOperation.cs @@ -20,6 +20,12 @@ public static void BuildRegisterConstantOperationModel(this ModelBuilder modelBu #endregion #region props + modelBuilder.Entity() + .Property(x => x.OpHash) + .IsFixedLength(true) + .HasMaxLength(51) + .IsRequired(); + modelBuilder.Entity() .Property(x => x.Address) .HasMaxLength(54); // expr @@ -42,8 +48,7 @@ public static void BuildRegisterConstantOperationModel(this ModelBuilder modelBu modelBuilder.Entity() .HasIndex(x => x.Address) - .HasFilter($@"""{nameof(RegisterConstantOperation.Address)}"" is not null") - .IsUnique(); + .HasFilter($@"""{nameof(RegisterConstantOperation.Address)}"" IS NOT NULL"); #endregion #region relations diff --git a/Tzkt.Data/Models/Operations/SetDelegateParametersOperation.cs b/Tzkt.Data/Models/Operations/SetDelegateParametersOperation.cs index 407c44c1d..b30d0ffa4 100644 --- a/Tzkt.Data/Models/Operations/SetDelegateParametersOperation.cs +++ b/Tzkt.Data/Models/Operations/SetDelegateParametersOperation.cs @@ -35,7 +35,10 @@ public static void BuildSetDelegateParametersOperationModel(this ModelBuilder mo .HasIndex(x => x.OpHash); modelBuilder.Entity() - .HasIndex(x => x.SenderId); + .HasIndex(x => new { x.SenderId, x.Id }); + + modelBuilder.Entity() + .HasIndex(x => x.ActivationCycle); #endregion #region relations diff --git a/Tzkt.Data/Models/Operations/SetDepositsLimitOperation.cs b/Tzkt.Data/Models/Operations/SetDepositsLimitOperation.cs index dd31d4470..546013016 100644 --- a/Tzkt.Data/Models/Operations/SetDepositsLimitOperation.cs +++ b/Tzkt.Data/Models/Operations/SetDepositsLimitOperation.cs @@ -18,6 +18,14 @@ public static void BuildSetDepositsLimitOperationModel(this ModelBuilder modelBu .HasKey(x => x.Id); #endregion + #region props + modelBuilder.Entity() + .Property(x => x.OpHash) + .IsFixedLength(true) + .HasMaxLength(51) + .IsRequired(); + #endregion + #region indexes modelBuilder.Entity() .HasIndex(x => x.Level); @@ -26,7 +34,7 @@ public static void BuildSetDepositsLimitOperationModel(this ModelBuilder modelBu .HasIndex(x => x.OpHash); modelBuilder.Entity() - .HasIndex(x => x.SenderId); + .HasIndex(x => new { x.SenderId, x.Id }); #endregion #region relations diff --git a/Tzkt.Data/Models/Operations/SmartRollupCementOperation.cs b/Tzkt.Data/Models/Operations/SmartRollupCementOperation.cs index 781c1969b..c5891fe47 100644 --- a/Tzkt.Data/Models/Operations/SmartRollupCementOperation.cs +++ b/Tzkt.Data/Models/Operations/SmartRollupCementOperation.cs @@ -34,12 +34,12 @@ public static void BuildSmartRollupCementOperationModel(this ModelBuilder modelB .HasIndex(x => x.OpHash); modelBuilder.Entity() - .HasIndex(x => x.SenderId); + .HasIndex(x => new { x.SmartRollupId, x.Id }); - modelBuilder.Entity() - .HasIndex(x => x.SmartRollupId); + modelBuilder.Entity() + .HasIndex(x => x.SenderId); - modelBuilder.Entity() + modelBuilder.Entity() .HasIndex(x => x.CommitmentId); #endregion diff --git a/Tzkt.Data/Models/Operations/SmartRollupExecuteOperation.cs b/Tzkt.Data/Models/Operations/SmartRollupExecuteOperation.cs index e6d3abe4a..5e5956ae6 100644 --- a/Tzkt.Data/Models/Operations/SmartRollupExecuteOperation.cs +++ b/Tzkt.Data/Models/Operations/SmartRollupExecuteOperation.cs @@ -43,7 +43,7 @@ public static void BuildSmartRollupExecuteOperationModel(this ModelBuilder model .HasIndex(x => x.SmartRollupId); modelBuilder.Entity() - .HasIndex(x => x.CommitmentId); + .HasIndex(x => new { x.CommitmentId, x.Id }); #endregion #region relations diff --git a/Tzkt.Data/Models/Operations/SmartRollupPublishOperation.cs b/Tzkt.Data/Models/Operations/SmartRollupPublishOperation.cs index bb8a41d48..bb13ad839 100644 --- a/Tzkt.Data/Models/Operations/SmartRollupPublishOperation.cs +++ b/Tzkt.Data/Models/Operations/SmartRollupPublishOperation.cs @@ -57,10 +57,10 @@ public static void BuildSmartRollupPublishOperationModel(this ModelBuilder model .HasIndex(x => x.SenderId); modelBuilder.Entity() - .HasIndex(x => x.SmartRollupId); + .HasIndex(x => x.CommitmentId); modelBuilder.Entity() - .HasIndex(x => x.CommitmentId); + .HasIndex(x => new { x.SmartRollupId, x.SenderId, x.Id }); modelBuilder.Entity() .HasIndex(x => new { x.SmartRollupId, x.BondStatus, x.SenderId }) diff --git a/Tzkt.Data/Models/Operations/SmartRollupRefuteOperation.cs b/Tzkt.Data/Models/Operations/SmartRollupRefuteOperation.cs index 170e4a81e..d3093117b 100644 --- a/Tzkt.Data/Models/Operations/SmartRollupRefuteOperation.cs +++ b/Tzkt.Data/Models/Operations/SmartRollupRefuteOperation.cs @@ -61,7 +61,7 @@ public static void BuildSmartRollupRefuteOperationModel(this ModelBuilder modelB .HasIndex(x => x.SmartRollupId); modelBuilder.Entity() - .HasIndex(x => x.GameId); + .HasIndex(x => new { x.GameId, x.Id }); #endregion #region relations diff --git a/Tzkt.Data/Models/Operations/TransactionOperation.cs b/Tzkt.Data/Models/Operations/TransactionOperation.cs index 801d7c0af..ce3f23887 100644 --- a/Tzkt.Data/Models/Operations/TransactionOperation.cs +++ b/Tzkt.Data/Models/Operations/TransactionOperation.cs @@ -59,6 +59,14 @@ public static void BuildTransactionOperationModel(this ModelBuilder modelBuilder modelBuilder.Entity() .HasIndex(x => x.Level); + modelBuilder.Entity() + .HasIndex(x => x.TargetId, $"IX_{nameof(TzktContext.TransactionOps)}_{nameof(TransactionOperation.TargetId)}_Partial") + .HasFilter($""" + "{nameof(TransactionOperation.Entrypoint)}" = 'transfer' + AND "{nameof(TransactionOperation.TokenTransfers)}" IS NULL + AND "{nameof(TransactionOperation.Status)}" = {(int)OperationStatus.Applied} + """); + modelBuilder.Entity() .HasIndex(x => x.OpHash); diff --git a/Tzkt.Data/Models/Operations/VdfRevelationOperation.cs b/Tzkt.Data/Models/Operations/VdfRevelationOperation.cs index afe214b04..417ed4643 100644 --- a/Tzkt.Data/Models/Operations/VdfRevelationOperation.cs +++ b/Tzkt.Data/Models/Operations/VdfRevelationOperation.cs @@ -49,7 +49,7 @@ public static void BuildVdfRevelationOperationModel(this ModelBuilder modelBuild .HasIndex(x => x.BakerId); modelBuilder.Entity() - .HasIndex(x => x.Cycle); + .HasIndex(x => new { x.Cycle, x.Id }); #endregion #region relations diff --git a/Tzkt.Data/Models/Scripts/BigMap.cs b/Tzkt.Data/Models/Scripts/BigMap.cs index d247f22ee..695aa8001 100644 --- a/Tzkt.Data/Models/Scripts/BigMap.cs +++ b/Tzkt.Data/Models/Scripts/BigMap.cs @@ -79,16 +79,9 @@ public static void BuildBigMapModel(this ModelBuilder modelBuilder) #region keys modelBuilder.Entity() .HasKey(x => x.Id); - - modelBuilder.Entity() - .HasAlternateKey(x => x.Ptr); #endregion #region indexes - modelBuilder.Entity() - .HasIndex(x => x.Id) - .IsUnique(); - modelBuilder.Entity() .HasIndex(x => x.Ptr) .IsUnique(); diff --git a/Tzkt.Data/Models/Scripts/BigMapKey.cs b/Tzkt.Data/Models/Scripts/BigMapKey.cs index c7c92288d..67832403e 100644 --- a/Tzkt.Data/Models/Scripts/BigMapKey.cs +++ b/Tzkt.Data/Models/Scripts/BigMapKey.cs @@ -31,6 +31,7 @@ public static void BuildBigMapKeyModel(this ModelBuilder modelBuilder) #region props modelBuilder.Entity() .Property(x => x.KeyHash) + .IsFixedLength(true) .HasMaxLength(54); modelBuilder.Entity() @@ -43,18 +44,11 @@ public static void BuildBigMapKeyModel(this ModelBuilder modelBuilder) #endregion #region indexes - modelBuilder.Entity() - .HasIndex(x => x.Id) - .IsUnique(); - - modelBuilder.Entity() - .HasIndex(x => x.BigMapPtr); - modelBuilder.Entity() .HasIndex(x => x.LastLevel); modelBuilder.Entity() - .HasIndex(x => new { x.BigMapPtr, x.Active }) + .HasIndex(x => x.BigMapPtr, $"IX_{nameof(TzktContext.BigMapKeys)}_{nameof(BigMapKey.BigMapPtr)}_Partial") .HasFilter($@"""{nameof(BigMapKey.Active)}"" = true"); modelBuilder.Entity() diff --git a/Tzkt.Data/Models/Scripts/BigMapUpdate.cs b/Tzkt.Data/Models/Scripts/BigMapUpdate.cs index e65235c07..d36ef4211 100644 --- a/Tzkt.Data/Models/Scripts/BigMapUpdate.cs +++ b/Tzkt.Data/Models/Scripts/BigMapUpdate.cs @@ -44,30 +44,26 @@ public static void BuildBigMapUpdateModel(this ModelBuilder modelBuilder) #region indexes modelBuilder.Entity() - .HasIndex(x => x.Id) - .IsUnique(); + .HasIndex(x => new { x.BigMapPtr, x.Id }); modelBuilder.Entity() - .HasIndex(x => x.BigMapPtr); - - modelBuilder.Entity() - .HasIndex(x => x.BigMapKeyId) - .HasFilter($@"""{nameof(BigMapUpdate.BigMapKeyId)}"" is not null"); + .HasIndex(x => new { x.BigMapKeyId, x.Id }) + .HasFilter($@"""{nameof(BigMapUpdate.BigMapKeyId)}"" IS NOT NULL"); modelBuilder.Entity() .HasIndex(x => x.Level); modelBuilder.Entity() .HasIndex(x => x.OriginationId) - .HasFilter($@"""{nameof(BigMapUpdate.OriginationId)}"" is not null"); + .HasFilter($@"""{nameof(BigMapUpdate.OriginationId)}"" IS NOT NULL"); modelBuilder.Entity() .HasIndex(x => x.TransactionId) - .HasFilter($@"""{nameof(BigMapUpdate.TransactionId)}"" is not null"); + .HasFilter($@"""{nameof(BigMapUpdate.TransactionId)}"" IS NOT NULL"); modelBuilder.Entity() .HasIndex(x => x.MigrationId) - .HasFilter($@"""{nameof(BigMapUpdate.MigrationId)}"" is not null"); + .HasFilter($@"""{nameof(BigMapUpdate.MigrationId)}"" IS NOT NULL"); #endregion } } diff --git a/Tzkt.Data/Models/Scripts/ContractEvent.cs b/Tzkt.Data/Models/Scripts/ContractEvent.cs index c8870cfb0..033362735 100644 --- a/Tzkt.Data/Models/Scripts/ContractEvent.cs +++ b/Tzkt.Data/Models/Scripts/ContractEvent.cs @@ -32,19 +32,9 @@ public static void BuildContractEventModel(this ModelBuilder modelBuilder) #endregion #region indexes - modelBuilder.Entity() - .HasIndex(x => x.Id) - .IsUnique(); - modelBuilder.Entity() .HasIndex(x => x.Level); - modelBuilder.Entity() - .HasIndex(x => x.ContractId); - - modelBuilder.Entity() - .HasIndex(x => x.ContractCodeHash); - modelBuilder.Entity() .HasIndex(x => x.TransactionId); diff --git a/Tzkt.Data/Models/Scripts/Script.cs b/Tzkt.Data/Models/Scripts/Script.cs index 08820f33d..b0222352e 100644 --- a/Tzkt.Data/Models/Scripts/Script.cs +++ b/Tzkt.Data/Models/Scripts/Script.cs @@ -71,11 +71,7 @@ public static void BuildScriptModel(this ModelBuilder modelBuilder) #region indexes modelBuilder.Entity