feat: Bildungsplan-Versionierung für Kompetenzkataloge, vollständig über MCP exponiert

Neue Bildungspläne wachsen je Fach klassenstufenweise hoch, sodass Kurse abhängig vom
Einschulungsjahr entweder dem alten oder dem neuen Bildungsplan folgen. CompetencyCatalogVersion
(Fach + Name + IsDefault) macht das abbildbar: CompetencyDomain bekommt eine VersionId, Kurse
wählen über LearningGroup.CompetencyCatalogVersionId (null = Standardversion des Fachs) welche
Version gilt. Migration legt für bestehende Kataloge automatisch eine Standardversion an, damit
alte Datenbanken unverändert weiterlaufen.

MCP: neue Tools für Versions-CRUD (get/create/update/delete_competency_plan_version,
update_group_competency_version), get_competency_catalog/create_competency_domain um optionalen
versionId-Parameter erweitert.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Sonnet 5 committed 2026-09-19 00:07:29 +02:00
1 parent 4ffba35eff
commit f97edff2fe
45 files changed
+1020 -163

No files matched your search

+34 -1
View File
@@ -15,7 +15,7 @@ public class LiteDbContext : IDisposable
/// Aktuelle Schema-Version. Migrationsschritte werden versioniert unter
/// <see cref="RunVersionedMigrations"/> ergänzt, statt bei jedem Start erneut
/// (idempotent, aber unnötig) über alle Daten zu laufen.
private const int CurrentSchemaVersion = 4;
private const int CurrentSchemaVersion = 5;
private readonly LiteDatabase _db;
@@ -61,6 +61,7 @@ public class LiteDbContext : IDisposable
public ILiteCollection<ParticipationSection> ParticipationSections => _db.GetCollection<ParticipationSection>("participation_sections");
public ILiteCollection<Subject> Subjects => _db.GetCollection<Subject>("subjects");
public ILiteCollection<CompetencyDomain> CompetencyDomains => _db.GetCollection<CompetencyDomain>("competency_domains");
public ILiteCollection<CompetencyCatalogVersion> CompetencyCatalogVersions => _db.GetCollection<CompetencyCatalogVersion>("competency_catalog_versions");
public ILiteCollection<ShorthandCode> ShorthandCodes => _db.GetCollection<ShorthandCode>("shorthand_codes");
public ILiteCollection<AlternativeLessonPath> AlternativeLessonPaths => _db.GetCollection<AlternativeLessonPath>("alternative_lesson_paths");
public ILiteCollection<TimetableSlot> TimetableSlots => _db.GetCollection<TimetableSlot>("timetable_slots");
@@ -262,6 +263,11 @@ public class LiteDbContext : IDisposable
MigrateLessonAlternativePaths();
version = 4;
}
if (version < 5)
{
MigrateCompetencyCatalogVersions();
version = 5;
}
WriteSchemaVersion(version);
}
@@ -485,6 +491,31 @@ public class LiteDbContext : IDisposable
}
}
/// <summary>Backfill für <see cref="CompetencyDomain.VersionId"/>: bestehende Bereiche (vor
/// Einführung der Bildungsplan-Versionierung, also ohne VersionId) bekommen je Fach genau eine
/// neu angelegte Standardversion ("Bestehender Kompetenzkatalog"). LearningGroup.CompetencyCatalogVersionId
/// bleibt bewusst null (= Standardversion) - siehe Doc-Kommentar auf dem Feld.</summary>
private void MigrateCompetencyCatalogVersions()
{
var defaultVersionBySubject = new Dictionary<Guid, Guid>();
foreach (var domain in CompetencyDomains.FindAll().ToList())
{
if (domain.VersionId != Guid.Empty) continue;
if (!defaultVersionBySubject.TryGetValue(domain.SubjectId, out var versionId))
{
var version = new CompetencyCatalogVersion
{
SubjectId = domain.SubjectId, Name = "Bestehender Kompetenzkatalog", IsDefault = true,
};
CompetencyCatalogVersions.Upsert(version);
versionId = version.Id;
defaultVersionBySubject[domain.SubjectId] = versionId;
}
domain.VersionId = versionId;
CompetencyDomains.Update(domain);
}
}
private void EnsureIndexes()
{
Students.EnsureIndex(x => x.LastName);
@@ -530,6 +561,8 @@ public class LiteDbContext : IDisposable
Subjects.EnsureIndex("ux_subject_name", BsonExpression.Create("LOWER(TRIM($.Name))"), unique: true);
CompetencyDomains.EnsureIndex(x => x.SubjectId);
CompetencyDomains.EnsureIndex(x => x.GradeLevel);
CompetencyDomains.EnsureIndex(x => x.VersionId);
CompetencyCatalogVersions.EnsureIndex(x => x.SubjectId);
ShorthandCodes.EnsureIndex("ux_shorthand_code", BsonExpression.Create("LOWER(TRIM($.Code))"), unique: true);
AlternativeLessonPaths.EnsureIndex("ux_alt_lesson_path_name", BsonExpression.Create("LOWER(TRIM($.Name))"), unique: true);
TimetableSlots.EnsureIndex(x => x.GroupId);