V2 upgrade
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace NostrStreamer.Database.Configuration;
|
||||
|
||||
public class IngestEndpointConfiguration : IEntityTypeConfiguration<IngestEndpoint>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<IngestEndpoint> builder)
|
||||
{
|
||||
builder.HasKey(a => a.Id);
|
||||
|
||||
builder.Property(a => a.Name)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.App)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Forward)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Cost)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Capabilities)
|
||||
.IsRequired();
|
||||
|
||||
builder.HasIndex(a => a.App)
|
||||
.IsUnique();
|
||||
}
|
||||
}
|
@ -19,7 +19,11 @@ public class PaymentsConfiguration : IEntityTypeConfiguration<Payment>
|
||||
|
||||
builder.Property(a => a.Created)
|
||||
.IsRequired();
|
||||
|
||||
|
||||
builder.Property(a => a.Nostr);
|
||||
builder.Property(a => a.Type)
|
||||
.IsRequired();
|
||||
|
||||
builder.HasOne(a => a.User)
|
||||
.WithMany(a => a.Payments)
|
||||
.HasForeignKey(a => a.PubKey);
|
||||
|
@ -11,7 +11,6 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
builder.Property(a => a.StreamKey)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Event);
|
||||
builder.Property(a => a.Balance)
|
||||
.IsRequired();
|
||||
|
||||
|
@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace NostrStreamer.Database.Configuration;
|
||||
|
||||
public class UserStreamConfiguration : IEntityTypeConfiguration<UserStream>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserStream> builder)
|
||||
{
|
||||
builder.HasKey(a => a.Id);
|
||||
builder.Property(a => a.ClientId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Starts)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Ends);
|
||||
|
||||
builder.Property(a => a.State)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Event)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Recording);
|
||||
|
||||
builder.HasOne(a => a.Endpoint)
|
||||
.WithMany()
|
||||
.HasForeignKey(a => a.EndpointId);
|
||||
|
||||
builder.HasOne(a => a.User)
|
||||
.WithMany(a => a.Streams)
|
||||
.HasForeignKey(a => a.PubKey);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace NostrStreamer.Database.Configuration;
|
||||
|
||||
public class UserStreamGuestConfiguration : IEntityTypeConfiguration<UserStreamGuest>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserStreamGuest> builder)
|
||||
{
|
||||
builder.HasKey(a => a.Id);
|
||||
builder.Property(a => a.PubKey)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Sig);
|
||||
builder.Property(a => a.Relay);
|
||||
builder.Property(a => a.Role);
|
||||
builder.Property(a => a.ZapSplit);
|
||||
|
||||
builder.HasOne(a => a.Stream)
|
||||
.WithMany(a => a.Guests)
|
||||
.HasForeignKey(a => a.StreamId);
|
||||
|
||||
builder.HasIndex(a => new {a.StreamId, a.PubKey})
|
||||
.IsUnique();
|
||||
}
|
||||
}
|
28
NostrStreamer/Database/IngestEndpoint.cs
Normal file
28
NostrStreamer/Database/IngestEndpoint.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace NostrStreamer.Database;
|
||||
|
||||
public class IngestEndpoint
|
||||
{
|
||||
public Guid Id { get; init; } = Guid.NewGuid();
|
||||
|
||||
public string Name { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Stream app name at ingest
|
||||
/// </summary>
|
||||
public string App { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Forward to VHost
|
||||
/// </summary>
|
||||
public string Forward { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Cost/min (milli-sats)
|
||||
/// </summary>
|
||||
public int Cost { get; init; } = 10_000;
|
||||
|
||||
/// <summary>
|
||||
/// Stream capability tags
|
||||
/// </summary>
|
||||
public List<string> Capabilities { get; init; } = new();
|
||||
}
|
@ -14,4 +14,14 @@ public class Payment
|
||||
public ulong Amount { get; init; }
|
||||
|
||||
public DateTime Created { get; init; } = DateTime.UtcNow;
|
||||
|
||||
public string? Nostr { get; init; }
|
||||
|
||||
public PaymentType Type { get; init; }
|
||||
}
|
||||
|
||||
public enum PaymentType
|
||||
{
|
||||
Topup = 0,
|
||||
Zap = 1
|
||||
}
|
@ -6,21 +6,25 @@ public class StreamerContext : DbContext
|
||||
{
|
||||
public StreamerContext()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public StreamerContext(DbContextOptions<StreamerContext> ctx) : base(ctx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(StreamerContext).Assembly);
|
||||
}
|
||||
|
||||
|
||||
public DbSet<User> Users => Set<User>();
|
||||
|
||||
public DbSet<Payment> Payments => Set<Payment>();
|
||||
|
||||
public DbSet<UserStream> Streams => Set<UserStream>();
|
||||
|
||||
public DbSet<UserStreamGuest> Guests => Set<UserStreamGuest>();
|
||||
|
||||
public DbSet<IngestEndpoint> Endpoints => Set<IngestEndpoint>();
|
||||
}
|
||||
|
@ -8,11 +8,6 @@ public class User
|
||||
/// Stream key
|
||||
/// </summary>
|
||||
public string StreamKey { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Most recent nostr event published
|
||||
/// </summary>
|
||||
public string? Event { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Milli sats balance
|
||||
@ -50,4 +45,5 @@ public class User
|
||||
public uint Version { get; set; }
|
||||
|
||||
public List<Payment> Payments { get; init; } = new();
|
||||
public List<UserStream> Streams { get; init; } = new();
|
||||
}
|
||||
|
@ -2,5 +2,38 @@ namespace NostrStreamer.Database;
|
||||
|
||||
public class UserStream
|
||||
{
|
||||
public Guid Id { get; init; } = Guid.NewGuid();
|
||||
|
||||
public string PubKey { get; init; } = null!;
|
||||
public User User { get; init; } = null!;
|
||||
|
||||
public string ClientId { get; init; } = null!;
|
||||
|
||||
public DateTime Starts { get; init; } = DateTime.UtcNow;
|
||||
|
||||
public DateTime? Ends { get; set; }
|
||||
|
||||
public UserStreamState State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Nostr Event for this stream
|
||||
/// </summary>
|
||||
public string Event { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Recording URL of ended stream
|
||||
/// </summary>
|
||||
public string? Recording { get; set; }
|
||||
|
||||
public Guid EndpointId { get; init; }
|
||||
public IngestEndpoint Endpoint { get; init; } = null!;
|
||||
|
||||
public List<UserStreamGuest> Guests { get; init; } = new();
|
||||
}
|
||||
|
||||
public enum UserStreamState
|
||||
{
|
||||
Planned = 1,
|
||||
Live = 2,
|
||||
Ended = 3
|
||||
}
|
19
NostrStreamer/Database/UserStreamGuest.cs
Normal file
19
NostrStreamer/Database/UserStreamGuest.cs
Normal file
@ -0,0 +1,19 @@
|
||||
namespace NostrStreamer.Database;
|
||||
|
||||
public class UserStreamGuest
|
||||
{
|
||||
public Guid Id { get; init; } = Guid.NewGuid();
|
||||
|
||||
public Guid StreamId { get; init; }
|
||||
public UserStream Stream { get; init; } = null!;
|
||||
|
||||
public string PubKey { get; init; } = null!;
|
||||
|
||||
public string? Relay { get; init; }
|
||||
|
||||
public string? Role { get; init; }
|
||||
|
||||
public string? Sig { get; init; }
|
||||
|
||||
public decimal ZapSplit { get; init; }
|
||||
}
|
Reference in New Issue
Block a user