using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace GermanApp.Infrastructure.Data.Migrations { /// public partial class AddLessonManagementTables : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.RenameColumn( name: "Level", table: "Lessons", newName: "Order"); migrationBuilder.AddColumn( name: "IsActive", table: "Lessons", type: "boolean", nullable: false, defaultValue: true); migrationBuilder.AddColumn( name: "LevelId", table: "Lessons", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "Topic", table: "Lessons", type: "character varying(100)", maxLength: 100, nullable: false, defaultValue: ""); migrationBuilder.CreateTable( name: "Levels", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Code = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), Order = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Levels", x => x.Id); }); migrationBuilder.CreateTable( name: "UserProgress", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), LessonId = table.Column(type: "integer", nullable: false), IsCompleted = table.Column(type: "boolean", nullable: false, defaultValue: false), QuizScore = table.Column(type: "integer", nullable: false, defaultValue: 0), LastAttemptDate = table.Column(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); } /// 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"); } } }