< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Persistence.EntityConfiguration.Bitcoin.UtxoEntityConfiguration
Assembly: NLightning.Infrastructure.Persistence
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Infrastructure.Persistence/EntityConfiguration/Bitcoin/UtxoEntityConfiguration.cs
Tag: 57_24045730253
Line coverage
0%
Covered lines: 0
Uncovered lines: 70
Coverable lines: 70
Total lines: 93
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ConfigureUtxoEntity(...)0%2040%
OptimizeConfigurationForSqlServer(...)100%210%
OptimizeConfigurationForPostgres(...)100%210%

File(s)

/home/runner/work/NLightning/NLightning/src/NLightning.Infrastructure.Persistence/EntityConfiguration/Bitcoin/UtxoEntityConfiguration.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.EntityFrameworkCore.Metadata.Builders;
 3
 4namespace NLightning.Infrastructure.Persistence.EntityConfiguration.Bitcoin;
 5
 6using Domain.Channels.Constants;
 7using Domain.Crypto.Constants;
 8using Entities.Bitcoin;
 9using Enums;
 10using ValueConverters;
 11
 12public static class UtxoEntityConfiguration
 13{
 14    public static void ConfigureUtxoEntity(this ModelBuilder modelBuilder, DatabaseType databaseType)
 15    {
 016        modelBuilder.Entity<UtxoEntity>(entity =>
 017        {
 018            // Set Primary Key
 019            entity.HasKey(e => new { e.TransactionId, e.Index });
 020
 021            // Set Required props
 022            entity.Property(e => e.AmountSats)
 023                  .IsRequired();
 024            entity.Property(e => e.BlockHeight)
 025                  .IsRequired();
 026            entity.Property(e => e.AddressIndex)
 027                  .IsRequired();
 028            entity.Property(e => e.IsAddressChange)
 029                  .IsRequired();
 030            entity.Property(e => e.AddressType)
 031                  .IsRequired();
 032
 033            // Set Optional props
 034            entity.Property(e => e.LockedToChannelId)
 035                  .IsRequired(false)
 036                  .HasConversion<ChannelIdConverter>();
 037            entity.Property(e => e.UsedInTransactionId)
 038                  .IsRequired(false)
 039                  .HasConversion<TxIdConverter>();
 040
 041            // Set converters
 042            entity.Property(x => x.TransactionId)
 043                  .HasConversion<TxIdConverter>();
 044
 045            // Set indexes
 046            entity.HasIndex(x => x.AddressType);
 047            entity.HasIndex(x => new { x.AddressIndex, x.IsAddressChange, x.AddressType });
 048            entity.HasIndex(x => x.LockedToChannelId);
 049            entity.HasIndex(x => x.UsedInTransactionId);
 050
 051            switch (databaseType)
 052            {
 053                case DatabaseType.MicrosoftSql:
 054                    OptimizeConfigurationForSqlServer(entity);
 055                    break;
 056                case DatabaseType.PostgreSql:
 057                    OptimizeConfigurationForPostgres(entity);
 058                    break;
 059                case DatabaseType.Sqlite:
 060                default:
 061                    // Nothing to be done
 062                    break;
 063            }
 064        });
 065    }
 66
 67    private static void OptimizeConfigurationForSqlServer(EntityTypeBuilder<UtxoEntity> entity)
 68    {
 069        entity.Property(e => e.TransactionId).HasColumnType($"varbinary({CryptoConstants.Sha256HashLen})");
 070        entity.Property(e => e.LockedToChannelId).HasColumnType($"varbinary({ChannelConstants.ChannelIdLength})");
 71
 072        entity.HasIndex(x => x.AddressType)
 073              .IsCreatedOnline();
 074        entity.HasIndex(x => new { x.AddressIndex, x.IsAddressChange, x.AddressType })
 075              .IsCreatedOnline();
 076        entity.HasIndex(x => x.LockedToChannelId)
 077              .IsCreatedOnline();
 078        entity.HasIndex(x => x.UsedInTransactionId)
 079              .IsCreatedOnline();
 080    }
 81
 82    private static void OptimizeConfigurationForPostgres(EntityTypeBuilder<UtxoEntity> entity)
 83    {
 084        entity.HasIndex(x => x.AddressType)
 085              .IsCreatedConcurrently();
 086        entity.HasIndex(x => new { x.AddressIndex, x.IsAddressChange, x.AddressType })
 087              .IsCreatedConcurrently();
 088        entity.HasIndex(x => x.LockedToChannelId)
 089              .IsCreatedConcurrently();
 090        entity.HasIndex(x => x.UsedInTransactionId)
 091              .IsCreatedConcurrently();
 092    }
 93}