- Created migration 20260607192743_AddLessonManagementTables - Renames old 'Level' column to 'Order' in Lessons table - Adds LevelId, Topic, IsActive columns to Lessons - Creates Levels table with Id, Name, Code, Order - Creates UserProgress table with UserId, LessonId, IsCompleted, QuizScore, LastAttemptDate - Adds foreign key from Lessons to Levels - Adds foreign keys from UserProgress to Users and Lessons - Adds unique indexes for Level.Code, Level.Order, Lesson.LevelId_Order, UserProgress.UserId_LessonId - Temporarily commented out seeding during migration creation to avoid EF Core tooling issues Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
159 lines
5.8 KiB
C#
159 lines
5.8 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
#nullable disable
|
|
|
|
namespace GermanApp.Infrastructure.Data.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddLessonManagementTables : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.RenameColumn(
|
|
name: "Level",
|
|
table: "Lessons",
|
|
newName: "Order");
|
|
|
|
migrationBuilder.AddColumn<bool>(
|
|
name: "IsActive",
|
|
table: "Lessons",
|
|
type: "boolean",
|
|
nullable: false,
|
|
defaultValue: true);
|
|
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "LevelId",
|
|
table: "Lessons",
|
|
type: "integer",
|
|
nullable: false,
|
|
defaultValue: 0);
|
|
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "Topic",
|
|
table: "Lessons",
|
|
type: "character varying(100)",
|
|
maxLength: 100,
|
|
nullable: false,
|
|
defaultValue: "");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Levels",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
Code = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
|
|
Order = table.Column<int>(type: "integer", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Levels", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "UserProgress",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
UserId = table.Column<int>(type: "integer", nullable: false),
|
|
LessonId = table.Column<int>(type: "integer", nullable: false),
|
|
IsCompleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
QuizScore = table.Column<int>(type: "integer", nullable: false, defaultValue: 0),
|
|
LastAttemptDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_UserProgress", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_UserProgress_Lessons_LessonId",
|
|
column: x => x.LessonId,
|
|
principalTable: "Lessons",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_UserProgress_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Lessons_LevelId_Order",
|
|
table: "Lessons",
|
|
columns: new[] { "LevelId", "Order" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Levels_Code",
|
|
table: "Levels",
|
|
column: "Code",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Levels_Order",
|
|
table: "Levels",
|
|
column: "Order",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserProgress_LessonId",
|
|
table: "UserProgress",
|
|
column: "LessonId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserProgress_UserId_LessonId",
|
|
table: "UserProgress",
|
|
columns: new[] { "UserId", "LessonId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "FK_Lessons_Levels_LevelId",
|
|
table: "Lessons",
|
|
column: "LevelId",
|
|
principalTable: "Levels",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropForeignKey(
|
|
name: "FK_Lessons_Levels_LevelId",
|
|
table: "Lessons");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Levels");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "UserProgress");
|
|
|
|
migrationBuilder.DropIndex(
|
|
name: "IX_Lessons_LevelId_Order",
|
|
table: "Lessons");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "IsActive",
|
|
table: "Lessons");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "LevelId",
|
|
table: "Lessons");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "Topic",
|
|
table: "Lessons");
|
|
|
|
migrationBuilder.RenameColumn(
|
|
name: "Order",
|
|
table: "Lessons",
|
|
newName: "Level");
|
|
}
|
|
}
|
|
}
|