DeutschLernen/GermanApp/Infrastructure/Data/Migrations/20260613125706_AddStorySegmentAndStoryProgressTables.cs
Lasse Rune Hansen 28c111f8e0 feat(backend/story-integration): Phase 5 - Apply database migration with EF design-time support
- Created AppDbContextFactory for EF Core design-time DbContext creation
- Added DOTNET_RUNNING_IN_EF environment variable checks to skip validation during migrations
- Modified MistralConnector, TtsService, VoskService to skip validation in EF design-time
- Updated Program.cs ValidateAiConfigurations to skip during migrations
- Applied migration 20260613125706_AddStorySegmentAndStoryProgressTables to database
- Updated feature documentation for Phase 5 completion

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-13 15:48:00 +02:00

279 lines
12 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace GermanApp.Infrastructure.Data.Migrations
{
/// <inheritdoc />
public partial class AddStorySegmentAndStoryProgressTables : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_QuizQuestions_Lessons_LessonId",
table: "QuizQuestions");
migrationBuilder.RenameColumn(
name: "LessonId",
table: "QuizQuestions",
newName: "QuizId");
migrationBuilder.RenameIndex(
name: "IX_QuizQuestions_LessonId_Order",
table: "QuizQuestions",
newName: "IX_QuizQuestions_QuizId_Order");
migrationBuilder.AddColumn<int>(
name: "Points",
table: "QuizQuestions",
type: "integer",
nullable: false,
defaultValue: 1);
migrationBuilder.AddColumn<int>(
name: "LevelId1",
table: "Lessons",
type: "integer",
nullable: true);
migrationBuilder.CreateTable(
name: "Quizzes",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
LessonId = table.Column<int>(type: "integer", nullable: false),
Title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
Description = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
PassingScore = table.Column<int>(type: "integer", nullable: false, defaultValue: 80),
TimeLimitMinutes = table.Column<int>(type: "integer", nullable: false, defaultValue: 0),
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
ShuffleQuestions = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Quizzes", x => x.Id);
table.ForeignKey(
name: "FK_Quizzes_Lessons_LessonId",
column: x => x.LessonId,
principalTable: "Lessons",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "StorySegments",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
LevelId = table.Column<int>(type: "integer", nullable: false),
LessonId = table.Column<int>(type: "integer", nullable: true),
Content = table.Column<string>(type: "text", nullable: false),
AudioUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
Order = table.Column<int>(type: "integer", nullable: false),
Title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
Theme = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
EstimatedReadingMinutes = table.Column<int>(type: "integer", nullable: false, defaultValue: 2),
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
LessonId1 = table.Column<int>(type: "integer", nullable: true),
LevelId1 = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_StorySegments", x => x.Id);
table.ForeignKey(
name: "FK_StorySegments_Lessons_LessonId",
column: x => x.LessonId,
principalTable: "Lessons",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_StorySegments_Lessons_LessonId1",
column: x => x.LessonId1,
principalTable: "Lessons",
principalColumn: "Id");
table.ForeignKey(
name: "FK_StorySegments_Levels_LevelId",
column: x => x.LevelId,
principalTable: "Levels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StorySegments_Levels_LevelId1",
column: x => x.LevelId1,
principalTable: "Levels",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "StoryProgress",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
LevelId = table.Column<int>(type: "integer", nullable: false),
StorySegmentId = table.Column<int>(type: "integer", nullable: false),
IsCompleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
UnlockedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
CompletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
UserId1 = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_StoryProgress", x => x.Id);
table.ForeignKey(
name: "FK_StoryProgress_Levels_LevelId",
column: x => x.LevelId,
principalTable: "Levels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StoryProgress_StorySegments_StorySegmentId",
column: x => x.StorySegmentId,
principalTable: "StorySegments",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StoryProgress_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StoryProgress_Users_UserId1",
column: x => x.UserId1,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Lessons_LevelId1",
table: "Lessons",
column: "LevelId1");
migrationBuilder.CreateIndex(
name: "IX_Quizzes_LessonId",
table: "Quizzes",
column: "LessonId");
migrationBuilder.CreateIndex(
name: "IX_StoryProgress_LevelId",
table: "StoryProgress",
column: "LevelId");
migrationBuilder.CreateIndex(
name: "IX_StoryProgress_StorySegmentId",
table: "StoryProgress",
column: "StorySegmentId");
migrationBuilder.CreateIndex(
name: "IX_StoryProgress_UserId_StorySegmentId",
table: "StoryProgress",
columns: new[] { "UserId", "StorySegmentId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_StoryProgress_UserId1",
table: "StoryProgress",
column: "UserId1");
migrationBuilder.CreateIndex(
name: "IX_StorySegments_LessonId",
table: "StorySegments",
column: "LessonId");
migrationBuilder.CreateIndex(
name: "IX_StorySegments_LessonId1",
table: "StorySegments",
column: "LessonId1");
migrationBuilder.CreateIndex(
name: "IX_StorySegments_LevelId_Order",
table: "StorySegments",
columns: new[] { "LevelId", "Order" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_StorySegments_LevelId1",
table: "StorySegments",
column: "LevelId1");
migrationBuilder.AddForeignKey(
name: "FK_Lessons_Levels_LevelId1",
table: "Lessons",
column: "LevelId1",
principalTable: "Levels",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_QuizQuestions_Quizzes_QuizId",
table: "QuizQuestions",
column: "QuizId",
principalTable: "Quizzes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Lessons_Levels_LevelId1",
table: "Lessons");
migrationBuilder.DropForeignKey(
name: "FK_QuizQuestions_Quizzes_QuizId",
table: "QuizQuestions");
migrationBuilder.DropTable(
name: "Quizzes");
migrationBuilder.DropTable(
name: "StoryProgress");
migrationBuilder.DropTable(
name: "StorySegments");
migrationBuilder.DropIndex(
name: "IX_Lessons_LevelId1",
table: "Lessons");
migrationBuilder.DropColumn(
name: "Points",
table: "QuizQuestions");
migrationBuilder.DropColumn(
name: "LevelId1",
table: "Lessons");
migrationBuilder.RenameColumn(
name: "QuizId",
table: "QuizQuestions",
newName: "LessonId");
migrationBuilder.RenameIndex(
name: "IX_QuizQuestions_QuizId_Order",
table: "QuizQuestions",
newName: "IX_QuizQuestions_LessonId_Order");
migrationBuilder.AddForeignKey(
name: "FK_QuizQuestions_Lessons_LessonId",
table: "QuizQuestions",
column: "LessonId",
principalTable: "Lessons",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}