using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace GermanApp.Infrastructure.Data.Migrations { /// public partial class AddStorySegmentAndStoryProgressTables : Migration { /// 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( name: "Points", table: "QuizQuestions", type: "integer", nullable: false, defaultValue: 1); migrationBuilder.AddColumn( name: "LevelId1", table: "Lessons", type: "integer", nullable: true); migrationBuilder.CreateTable( name: "Quizzes", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), LessonId = table.Column(type: "integer", nullable: false), Title = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Description = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), PassingScore = table.Column(type: "integer", nullable: false, defaultValue: 80), TimeLimitMinutes = table.Column(type: "integer", nullable: false, defaultValue: 0), IsActive = table.Column(type: "boolean", nullable: false, defaultValue: true), ShuffleQuestions = table.Column(type: "boolean", nullable: false, defaultValue: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), LevelId = table.Column(type: "integer", nullable: false), LessonId = table.Column(type: "integer", nullable: true), Content = table.Column(type: "text", nullable: false), AudioUrl = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), Order = table.Column(type: "integer", nullable: false), Title = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Theme = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), EstimatedReadingMinutes = table.Column(type: "integer", nullable: false, defaultValue: 2), IsActive = table.Column(type: "boolean", nullable: false, defaultValue: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), LessonId1 = table.Column(type: "integer", nullable: true), LevelId1 = table.Column(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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), LevelId = table.Column(type: "integer", nullable: false), StorySegmentId = table.Column(type: "integer", nullable: false), IsCompleted = table.Column(type: "boolean", nullable: false, defaultValue: false), UnlockedAt = table.Column(type: "timestamp with time zone", nullable: false), CompletedAt = table.Column(type: "timestamp with time zone", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), UserId1 = table.Column(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); } /// 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); } } }