:drunk: No idea what did AI did
This commit is contained in:
@ -1,11 +1,17 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using DysonNetwork.Common.Models;
|
||||
using DysonNetwork.Pass.Features.Auth.Models;
|
||||
using DysonNetwork.Sphere.Permission;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using NodaTime;
|
||||
using Quartz;
|
||||
using Account = DysonNetwork.Pass.Features.Auth.Models.Account;
|
||||
using AccountConnection = DysonNetwork.Pass.Features.Auth.Models.AccountConnection;
|
||||
using AccountAuthFactor = DysonNetwork.Pass.Features.Auth.Models.AccountAuthFactor;
|
||||
using AuthSession = DysonNetwork.Pass.Features.Auth.Models.AuthSession;
|
||||
using AuthChallenge = DysonNetwork.Pass.Features.Auth.Models.AuthChallenge;
|
||||
|
||||
namespace DysonNetwork.Pass.Data;
|
||||
|
||||
@ -19,11 +25,9 @@ public class PassDatabase(
|
||||
public DbSet<PermissionGroupMember> PermissionGroupMembers { get; set; }
|
||||
|
||||
public DbSet<MagicSpell> MagicSpells { get; set; }
|
||||
public DbSet<Account> Accounts { get; set; }
|
||||
public DbSet<AccountConnection> AccountConnections { get; set; }
|
||||
public DbSet<Profile> AccountProfiles { get; set; }
|
||||
public DbSet<AccountContact> AccountContacts { get; set; }
|
||||
public DbSet<AccountAuthFactor> AccountAuthFactors { get; set; }
|
||||
public DbSet<Account> Accounts { get; set; } = null!;
|
||||
public DbSet<AccountConnection> AccountConnections { get; set; } = null!;
|
||||
public DbSet<AccountAuthFactor> AccountAuthFactors { get; set; } = null!;
|
||||
public DbSet<Relationship> AccountRelationships { get; set; }
|
||||
public DbSet<Notification> Notifications { get; set; }
|
||||
public DbSet<Badge> Badges { get; set; }
|
||||
@ -77,6 +81,213 @@ public class PassDatabase(
|
||||
.WithMany(a => a.IncomingRelationships)
|
||||
.HasForeignKey(r => r.RelatedId);
|
||||
|
||||
// Configure AuthSession
|
||||
modelBuilder.Entity<AuthSession>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValueSql("gen_random_uuid()");
|
||||
|
||||
entity.Property(e => e.Label)
|
||||
.HasMaxLength(500);
|
||||
|
||||
entity.Property(e => e.LastGrantedAt)
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.ExpiredAt)
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.AccessToken)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
entity.Property(e => e.RefreshToken)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
entity.Property(e => e.IpAddress)
|
||||
.HasMaxLength(128);
|
||||
|
||||
entity.Property(e => e.UserAgent)
|
||||
.HasMaxLength(500);
|
||||
|
||||
entity.HasOne(s => s.Account)
|
||||
.WithMany(a => a.Sessions)
|
||||
.HasForeignKey(s => s.AccountId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
entity.HasOne(s => s.Challenge)
|
||||
.WithMany()
|
||||
.HasForeignKey(s => s.ChallengeId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
entity.Property(e => e.Metadata)
|
||||
.HasColumnType("jsonb");
|
||||
});
|
||||
|
||||
// Configure AuthChallenge
|
||||
modelBuilder.Entity<AuthChallenge>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
|
||||
entity.Property(e => e.Type)
|
||||
.IsRequired()
|
||||
.HasConversion<string>();
|
||||
|
||||
entity.Property(e => e.Platform)
|
||||
.IsRequired()
|
||||
.HasConversion<string>();
|
||||
|
||||
entity.Property(e => e.CreatedAt)
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.ExpiredAt);
|
||||
|
||||
entity.Property(e => e.StepRemain)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(1);
|
||||
|
||||
entity.Property(e => e.StepTotal)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(1);
|
||||
|
||||
entity.Property(e => e.FailedAttempts)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(0);
|
||||
|
||||
entity.Property(e => e.IpAddress)
|
||||
.HasMaxLength(128);
|
||||
|
||||
entity.Property(e => e.UserAgent)
|
||||
.HasMaxLength(512);
|
||||
|
||||
entity.Property(e => e.DeviceId)
|
||||
.HasMaxLength(256);
|
||||
|
||||
entity.Property(e => e.Nonce)
|
||||
.HasMaxLength(1024);
|
||||
|
||||
entity.Property(e => e.BlacklistFactors)
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
entity.Property(e => e.Audiences)
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
entity.Property(e => e.Scopes)
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
entity.HasOne<Account>()
|
||||
.WithMany(a => a.Challenges)
|
||||
.HasForeignKey(e => e.AccountId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
entity.Ignore(e => e.Location); // Ignore Point type as it's not directly supported by EF Core
|
||||
});
|
||||
|
||||
// Configure AccountAuthFactor
|
||||
modelBuilder.Entity<AccountAuthFactor>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValueSql("gen_random_uuid()");
|
||||
|
||||
entity.Property(e => e.FactorType)
|
||||
.IsRequired()
|
||||
.HasConversion<string>();
|
||||
|
||||
entity.Property(e => e.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
entity.Property(e => e.Description)
|
||||
.HasMaxLength(500);
|
||||
|
||||
entity.Property(e => e.Secret)
|
||||
.IsRequired()
|
||||
.HasMaxLength(1024);
|
||||
|
||||
entity.Property(e => e.IsDefault)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
entity.Property(e => e.IsBackup)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
entity.Property(e => e.LastUsedAt);
|
||||
entity.Property(e => e.EnabledAt);
|
||||
entity.Property(e => e.DisabledAt);
|
||||
|
||||
entity.Property(e => e.Metadata)
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
entity.HasOne(f => f.Account)
|
||||
.WithMany(a => a.AuthFactors)
|
||||
.HasForeignKey(f => f.AccountId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// Remove the incorrect relationship configuration
|
||||
// The relationship is already defined in the AuthSession configuration
|
||||
});
|
||||
|
||||
// Configure Account
|
||||
modelBuilder.Entity<Account>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
|
||||
entity.Property(e => e.Email)
|
||||
.IsRequired()
|
||||
.HasMaxLength(256);
|
||||
|
||||
entity.Property(e => e.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(256);
|
||||
|
||||
entity.Property(e => e.Status)
|
||||
.HasMaxLength(32);
|
||||
|
||||
entity.Property(e => e.CreatedAt)
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.UpdatedAt)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
// Configure AccountConnection
|
||||
modelBuilder.Entity<AccountConnection>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
|
||||
entity.Property(e => e.Provider)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
entity.Property(e => e.ProviderId)
|
||||
.IsRequired()
|
||||
.HasMaxLength(256);
|
||||
|
||||
entity.Property(e => e.DisplayName)
|
||||
.HasMaxLength(256);
|
||||
|
||||
entity.Property(e => e.AccessToken)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
entity.Property(e => e.RefreshToken)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
entity.Property(e => e.ExpiresAt);
|
||||
|
||||
entity.Property(e => e.ProfileData)
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
entity.HasOne<Account>()
|
||||
.WithMany(a => a.Connections)
|
||||
.HasForeignKey(e => e.AccountId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
// Automatically apply soft-delete filter to all entities inheriting BaseModel
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
{
|
||||
|
Reference in New Issue
Block a user