| | 1 | | using Microsoft.EntityFrameworkCore; |
| | 2 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | 3 | |
|
| | 4 | | namespace NLightning.Infrastructure.Persistence.EntityConfiguration.Bitcoin; |
| | 5 | |
|
| | 6 | | using Domain.Channels.Constants; |
| | 7 | | using Domain.Crypto.Constants; |
| | 8 | | using Entities.Bitcoin; |
| | 9 | | using Enums; |
| | 10 | | using ValueConverters; |
| | 11 | |
|
| | 12 | | public static class WatchedTransactionEntityConfiguration |
| | 13 | | { |
| | 14 | | public static void ConfigureWatchedTransactionEntity(this ModelBuilder modelBuilder, DatabaseType databaseType) |
| | 15 | | { |
| 0 | 16 | | modelBuilder.Entity<WatchedTransactionEntity>(entity => |
| 0 | 17 | | { |
| 0 | 18 | | // Set PrimaryKey |
| 0 | 19 | | entity.HasKey(e => new { e.TransactionId }); |
| 0 | 20 | |
|
| 0 | 21 | | // Set required props |
| 0 | 22 | | entity.Property(e => e.TransactionId) |
| 0 | 23 | | .HasConversion<TxIdConverter>() |
| 0 | 24 | | .IsRequired(); |
| 0 | 25 | | entity.Property(e => e.ChannelId) |
| 0 | 26 | | .HasConversion<ChannelIdConverter>() |
| 0 | 27 | | .IsRequired(); |
| 0 | 28 | | entity.Property(e => e.RequiredDepth).IsRequired(); |
| 0 | 29 | | entity.Property(e => e.CreatedAt).IsRequired(); |
| 0 | 30 | |
|
| 0 | 31 | | // Configure optional props |
| 0 | 32 | | entity.Property(e => e.FirstSeenAtHeight).IsRequired(false); |
| 0 | 33 | | entity.Property(e => e.CompletedAt).IsRequired(false); |
| 0 | 34 | |
|
| 0 | 35 | | if (databaseType == DatabaseType.MicrosoftSql) |
| 0 | 36 | | OptimizeConfigurationForSqlServer(entity); |
| 0 | 37 | | }); |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | private static void OptimizeConfigurationForSqlServer(EntityTypeBuilder<WatchedTransactionEntity> entity) |
| | 41 | | { |
| 0 | 42 | | entity.Property(e => e.ChannelId).HasColumnType($"varbinary({ChannelConstants.ChannelIdLength})"); |
| 0 | 43 | | entity.Property(e => e.TransactionId).HasColumnType($"varbinary({CryptoConstants.Sha256HashLen})"); |
| 0 | 44 | | } |
| | 45 | | } |