🐛 Fix account profile relationship
This commit is contained in:
parent
aa0d2ab3c4
commit
8e8a120a90
@ -54,16 +54,13 @@ public class AccountService(
|
||||
public async Task EnsureAccountProfileCreated()
|
||||
{
|
||||
var accountsId = await db.Accounts.Select(a => a.Id).ToListAsync();
|
||||
var missingId = await db.AccountProfiles
|
||||
.IgnoreAutoIncludes()
|
||||
.Where(p => !accountsId.Contains(p.AccountId))
|
||||
.Select(p => p.AccountId)
|
||||
.ToListAsync();
|
||||
var existingId = await db.AccountProfiles.Select(p => p.AccountId).ToListAsync();
|
||||
var missingId = accountsId.Except(existingId).ToList();
|
||||
|
||||
if (missingId.Count != 0)
|
||||
{
|
||||
var newProfiles = missingId.Select(id => new Profile { AccountId = id }).ToList();
|
||||
await db.BulkInsertAsync(newProfiles, config => config.ConflictOption = ConflictOption.Ignore);
|
||||
var newProfiles = missingId.Select(id => new Profile { Id = Guid.NewGuid(), AccountId = id }).ToList();
|
||||
await db.BulkInsertAsync(newProfiles);
|
||||
}
|
||||
}
|
||||
}
|
@ -140,11 +140,6 @@ public class AppDatabase(
|
||||
.HasForeignKey(pg => pg.GroupId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<Account.Account>()
|
||||
.HasOne(a => a.Profile)
|
||||
.WithOne(p => p.Account)
|
||||
.HasForeignKey<Account.Profile>(p => p.Id);
|
||||
|
||||
modelBuilder.Entity<Account.Relationship>()
|
||||
.HasKey(r => new { FromAccountId = r.AccountId, ToAccountId = r.RelatedId });
|
||||
modelBuilder.Entity<Account.Relationship>()
|
||||
|
3449
DysonNetwork.Sphere/Migrations/20250521181143_FixProfileRelationship.Designer.cs
generated
Normal file
3449
DysonNetwork.Sphere/Migrations/20250521181143_FixProfileRelationship.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,52 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DysonNetwork.Sphere.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FixProfileRelationship : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_account_profiles_accounts_id",
|
||||
table: "account_profiles");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_account_profiles_account_id",
|
||||
table: "account_profiles",
|
||||
column: "account_id",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_account_profiles_accounts_account_id",
|
||||
table: "account_profiles",
|
||||
column: "account_id",
|
||||
principalTable: "accounts",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_account_profiles_accounts_account_id",
|
||||
table: "account_profiles");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_account_profiles_account_id",
|
||||
table: "account_profiles");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_account_profiles_accounts_id",
|
||||
table: "account_profiles",
|
||||
column: "id",
|
||||
principalTable: "accounts",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
@ -529,6 +529,7 @@ namespace DysonNetwork.Sphere.Migrations
|
||||
modelBuilder.Entity("DysonNetwork.Sphere.Account.Profile", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
@ -603,6 +604,10 @@ namespace DysonNetwork.Sphere.Migrations
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_account_profiles");
|
||||
|
||||
b.HasIndex("AccountId")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_account_profiles_account_id");
|
||||
|
||||
b.HasIndex("BackgroundId")
|
||||
.HasDatabaseName("ix_account_profiles_background_id");
|
||||
|
||||
@ -2699,18 +2704,18 @@ namespace DysonNetwork.Sphere.Migrations
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Sphere.Account.Profile", b =>
|
||||
{
|
||||
b.HasOne("DysonNetwork.Sphere.Account.Account", "Account")
|
||||
.WithOne("Profile")
|
||||
.HasForeignKey("DysonNetwork.Sphere.Account.Profile", "AccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_account_profiles_accounts_account_id");
|
||||
|
||||
b.HasOne("DysonNetwork.Sphere.Storage.CloudFile", "Background")
|
||||
.WithMany()
|
||||
.HasForeignKey("BackgroundId")
|
||||
.HasConstraintName("fk_account_profiles_files_background_id");
|
||||
|
||||
b.HasOne("DysonNetwork.Sphere.Account.Account", "Account")
|
||||
.WithOne("Profile")
|
||||
.HasForeignKey("DysonNetwork.Sphere.Account.Profile", "Id")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_account_profiles_accounts_id");
|
||||
|
||||
b.HasOne("DysonNetwork.Sphere.Storage.CloudFile", "Picture")
|
||||
.WithMany()
|
||||
.HasForeignKey("PictureId")
|
||||
|
Loading…
x
Reference in New Issue
Block a user