fix datamodel

This commit is contained in:
beo3000 2025-12-21 11:42:59 +01:00
parent 6c43c85cb4
commit d653225c5f
8 changed files with 60 additions and 8 deletions

View File

@ -7,17 +7,16 @@ dotnet tool update --global dotnet-ef --version 9.0.11
## Update-DB:
```
dotnet ef migrations add [KEYWORDABOUTCHANGE] --project src/AIMS.Infrastructure --startup-project src/AIMS.Web
dotnet ef migrations add [Initial_App] --project src/Koogle.Infrastructure --startup-project src/Koogle.Web --context AppDbContext --output-dir Data/Migrations
dotnet ef database update -p src/Koogle.Infrastructure -s src/Koogle.Web --context AppDbContext
dotnet ef migrations add Initial_App --project src/Koogle.Infrastructure --startup-project src/Koogle.Web --context AppDbContext --output-dir Data/Migrations
dotnet ef migrations add Initial_Auth --project src/Koogle.Infrastructure --startup-project src/Koogle.Web --context AppIdentityDbContext --output-dir Identity/Migrations
dotnet ef migrations add [Initial_Auth] --project src/Koogle.Infrastructure --startup-project src/Koogle.Web --context AppIdentityDbContext --output-dir Identity/Migrations
dotnet ef database update -p src/AIMS.Infrastructure -s src/AIMS.Web
dotnet ef database update -p src/Koogle.Infrastructure -s src/Koogle.Web --context AppIdentityDbContext
dotnet ef database update -p src/Koogle.Infrastructure -s src/Koogle.Web --context AppDbContext
```

View File

@ -41,6 +41,23 @@ public class DayPersonConfiguration : IEntityTypeConfiguration<DayPerson>
.HasPrincipalKey(p => new { p.Id, p.ClubId })
.OnDelete(DeleteBehavior.Cascade);
builder.HasIndex(x => x.ClubId);
builder.HasIndex(x => x.DayId);
builder.HasIndex(x => x.PersonId);
// ✅ Matching Query Filter(verhindert die Warnung 10622)
// DayPerson wird automatisch ausgeblendet, wenn Club/Day/Person soft-deleted ist.
builder.HasQueryFilter(dp =>
!dp.Day.IsDeleted &&
!dp.Person.IsDeleted &&
!dp.Club.IsDeleted
);
builder.HasIndex(x => x.ClubId);
builder.HasIndex(x => x.DayId);
builder.HasIndex(x => x.PersonId);

View File

@ -49,6 +49,15 @@ public class ExpenseTriggerConfiguration : IEntityTypeConfiguration<ExpenseTrigg
builder.HasIndex(x => x.TriggerId);
builder.HasIndex(x => x.ClubId);
// ✅ Matching Query Filter: Zuordnung verschwindet automatisch,
// wenn Club/Expense/Trigger soft-deleted sind.
builder.HasQueryFilter(et =>
!et.Club.IsDeleted &&
!et.Expense.IsDeleted &&
!et.Trigger.IsDeleted
);
}
}

View File

@ -28,6 +28,16 @@ public class GamePersonConfiguration : IEntityTypeConfiguration<GamePerson>
.OnDelete(DeleteBehavior.Cascade);
builder.HasIndex(x => x.PersonId);
// ✅ Matching Query Filter:
// GamePerson nur sichtbar, wenn Game + Person + Day des Games nicht soft-deleted sind.
builder.HasQueryFilter(gp =>
!gp.Game.IsDeleted &&
!gp.Person.IsDeleted &&
!gp.Game.Day.IsDeleted
);
}
}

View File

@ -63,7 +63,16 @@ public class PersonExpenseConfiguration : IEntityTypeConfiguration<PersonExpense
builder.HasIndex(x => x.DayId);
builder.HasIndex(x => x.GameId);
builder.HasQueryFilter(x => !x.IsDeleted);
builder.HasQueryFilter(pe =>
// required Principals müssen sichtbar sein
!pe.Person.IsDeleted &&
!pe.Day.IsDeleted &&
!pe.Expense.IsDeleted &&
// optionales Game: entweder kein Game, oder Game + dessen Day sichtbar
(pe.GameId == null || (!pe.Game!.IsDeleted && !pe.Game!.Day.IsDeleted))
);
}
}

View File

@ -41,5 +41,13 @@ public class UserProfileClubConfiguration : IEntityTypeConfiguration<UserProfile
builder.HasIndex(x => x.ClubId);
// ✅ Matching Query Filter
builder.HasQueryFilter(upc =>
!upc.UserProfile.IsDeleted &&
!upc.Club.IsDeleted
);
}
}

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Koogle.Infrastructure.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20251221085745_Initial_App")]
[Migration("20251221103855_Initial_App")]
partial class Initial_App
{
/// <inheritdoc />