| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | |
| | | 3 | | namespace NLightning.Infrastructure.Persistence.Contexts; |
| | | 4 | | |
| | | 5 | | using Entities.Bitcoin; |
| | | 6 | | using Entities.Channel; |
| | | 7 | | using Entities.Node; |
| | | 8 | | using EntityConfiguration.Bitcoin; |
| | | 9 | | using EntityConfiguration.Channel; |
| | | 10 | | using EntityConfiguration.Node; |
| | | 11 | | using Enums; |
| | | 12 | | using Providers; |
| | | 13 | | |
| | | 14 | | public class NLightningDbContext : DbContext |
| | | 15 | | { |
| | | 16 | | private readonly DatabaseType _databaseType; |
| | | 17 | | |
| | | 18 | | public NLightningDbContext(DbContextOptions<NLightningDbContext> options, DatabaseTypeProvider databaseTypeProvider) |
| | 0 | 19 | | : base(options) |
| | | 20 | | { |
| | 0 | 21 | | _databaseType = databaseTypeProvider.DatabaseType; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | // Bitcoin DbSets |
| | 0 | 25 | | public DbSet<BlockchainStateEntity> BlockchainStates { get; set; } |
| | 0 | 26 | | public DbSet<WatchedTransactionEntity> WatchedTransactions { get; set; } |
| | | 27 | | |
| | | 28 | | // Channel DbSets |
| | 0 | 29 | | public DbSet<ChannelEntity> Channels { get; set; } |
| | 0 | 30 | | public DbSet<ChannelConfigEntity> ChannelConfigs { get; set; } |
| | 0 | 31 | | public DbSet<ChannelKeySetEntity> ChannelKeySets { get; set; } |
| | 0 | 32 | | public DbSet<HtlcEntity> Htlcs { get; set; } |
| | | 33 | | |
| | | 34 | | // Node DbSets |
| | 0 | 35 | | public DbSet<PeerEntity> Peers { get; set; } |
| | | 36 | | |
| | | 37 | | protected override void OnModelCreating(ModelBuilder modelBuilder) |
| | | 38 | | { |
| | 0 | 39 | | base.OnModelCreating(modelBuilder); |
| | | 40 | | |
| | | 41 | | // Bitcoin entities |
| | 0 | 42 | | modelBuilder.ConfigureBlockchainStateEntity(_databaseType); |
| | 0 | 43 | | modelBuilder.ConfigureWatchedTransactionEntity(_databaseType); |
| | | 44 | | |
| | | 45 | | // Channel entities |
| | 0 | 46 | | modelBuilder.ConfigureChannelEntity(_databaseType); |
| | 0 | 47 | | modelBuilder.ConfigureChannelConfigEntity(_databaseType); |
| | 0 | 48 | | modelBuilder.ConfigureChannelKeySetEntity(_databaseType); |
| | 0 | 49 | | modelBuilder.ConfigureHtlcEntity(_databaseType); |
| | | 50 | | |
| | | 51 | | // Node entities |
| | 0 | 52 | | modelBuilder.ConfigurePeerEntity(_databaseType); |
| | 0 | 53 | | } |
| | | 54 | | } |