Skip to content

Commit f860291

Browse files
Adding rowId to StoreRecords Entity and table
1 parent 5b0ab1c commit f860291

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/Nethereum.Mud.Repositories.EntityFramework/BlockProgressRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task UpsertProgressAsync(BigInteger blockNumber)
3838
catch (DbUpdateException ex) when (ex.InnerException?.Message.Contains("String or binary data would be truncated") ?? false)
3939
{
4040
throw new DbUpdateException(
41-
$"{nameof(BlockProgressRepository<TDbContext>)} Data Truncation Rrror. Ensure that the LastBlockProcessed column length is {ColumnLengths.BigIntegerLength}."
41+
$"{nameof(BlockProgressRepository<TDbContext>)} Data Truncation Error. Ensure that the LastBlockProcessed column length is {ColumnLengths.BigIntegerLength}."
4242
, ex);
4343
}
4444
}

src/Nethereum.Mud.Repositories.Postgres/MudPostgresStoreRecordsDbContext.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Microsoft.Extensions.Configuration;
55
using Nethereum.BlockchainProcessing.BlockStorage.Entities;
66
using Nethereum.Mud.Repositories.EntityFramework;
7+
using System.Collections.Generic;
8+
using System.Threading.Tasks;
79

810
namespace Nethereum.Mud.Repositories.Postgres
911
{
@@ -17,10 +19,12 @@ public MudPostgresStoreRecordsDbContext()
1719
public MudPostgresStoreRecordsDbContext(DbContextOptions<MudPostgresStoreRecordsDbContext> options)
1820
: base(options) {
1921

20-
22+
2123

2224
}
23-
25+
26+
27+
2428
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2529
{
2630
if (!optionsBuilder.IsConfigured)
@@ -36,6 +40,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3640

3741
modelBuilder.Entity<BlockProgress>().HasKey(r => r.RowIndex);
3842

43+
modelBuilder.Entity<StoredRecord>()
44+
.Property(e => e.RowId)
45+
.ValueGeneratedOnAdd();
46+
47+
modelBuilder.Entity<StoredRecord>()
48+
.HasIndex(r => new { r.RowId })
49+
.HasDatabaseName("IX_RowId");
50+
3951
// Set primary key based on Address, TableId, and Key
4052
modelBuilder.Entity<StoredRecord>()
4153
.HasKey(r => new { r.AddressBytes, r.TableIdBytes, r.KeyBytes });

src/Nethereum.Mud.Repositories.Postgres/MudPostgresStoreRecordsProcessingService.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using Nethereum.Web3;
33
using System.Numerics;
44
using Microsoft.Extensions.Logging;
5-
using Nethereum.Mud;
65
using Nethereum.Mud.EncodingDecoding;
76
using Nethereum.Mud.Repositories.EntityFramework;
87
using System.Threading.Tasks;
98
using System.Threading;
109

1110
namespace Nethereum.Mud.Repositories.Postgres
1211
{
12+
1313
public class MudPostgresStoreRecordsProcessingService
1414
{
1515
public MudPostgresStoreRecordsProcessingService(MudPostgresStoreRecordsDbContext context, ILogger logger)
@@ -19,10 +19,10 @@ public MudPostgresStoreRecordsProcessingService(MudPostgresStoreRecordsDbContext
1919
}
2020

2121
public MudPostgresStoreRecordsDbContext Context { get; }
22-
public ILogger Logger { get; set; }
22+
public ILogger Logger { get; set; }
2323
public string Address { get; set; }
2424
public string RpcUrl { get; set; }
25-
public BigInteger StartAtBlockNumberIfNotProcessed { get; set; } = 0;
25+
public BigInteger StartAtBlockNumberIfNotProcessed { get; set; } = 0;
2626
public int NumberOfBlocksToProcessPerRequest { get; set; } = 1000;
2727
public int RetryWeight { get; set; } = 50;
2828

@@ -42,4 +42,8 @@ await processor.ExecuteAsync(
4242

4343
}
4444
}
45+
4546
}
47+
48+
49+

0 commit comments

Comments
 (0)