using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace DramaLing.Api.Migrations { /// public partial class FixFlashcardColumnNaming : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_pronunciation_assessments_study_sessions_study_session_id", table: "pronunciation_assessments"); migrationBuilder.DropTable( name: "study_records"); migrationBuilder.DropTable( name: "test_results"); migrationBuilder.DropTable( name: "study_cards"); migrationBuilder.DropTable( name: "study_sessions"); migrationBuilder.DropIndex( name: "IX_PronunciationAssessment_Session", table: "pronunciation_assessments"); migrationBuilder.DropColumn( name: "study_session_id", table: "pronunciation_assessments"); migrationBuilder.DropColumn( name: "FilledQuestionText", table: "flashcards"); migrationBuilder.DropColumn( name: "LastQuestionType", table: "flashcards"); migrationBuilder.DropColumn( name: "Repetitions", table: "flashcards"); migrationBuilder.DropColumn( name: "ReviewHistory", table: "flashcards"); migrationBuilder.DropColumn( name: "Synonyms", table: "flashcards"); migrationBuilder.DropColumn( name: "easiness_factor", table: "flashcards"); migrationBuilder.DropColumn( name: "interval_days", table: "flashcards"); migrationBuilder.DropColumn( name: "last_reviewed_at", table: "flashcards"); migrationBuilder.DropColumn( name: "mastery_level", table: "flashcards"); migrationBuilder.DropColumn( name: "next_review_date", table: "flashcards"); migrationBuilder.DropColumn( name: "times_correct", table: "flashcards"); migrationBuilder.DropColumn( name: "times_reviewed", table: "flashcards"); migrationBuilder.RenameColumn( name: "Word", table: "flashcards", newName: "word"); migrationBuilder.RenameColumn( name: "Translation", table: "flashcards", newName: "translation"); migrationBuilder.RenameColumn( name: "Pronunciation", table: "flashcards", newName: "pronunciation"); migrationBuilder.RenameColumn( name: "Example", table: "flashcards", newName: "example"); migrationBuilder.RenameColumn( name: "Definition", table: "flashcards", newName: "definition"); migrationBuilder.AlterColumn( name: "definition", table: "flashcards", type: "TEXT", nullable: true, oldClrType: typeof(string), oldType: "TEXT"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.RenameColumn( name: "word", table: "flashcards", newName: "Word"); migrationBuilder.RenameColumn( name: "translation", table: "flashcards", newName: "Translation"); migrationBuilder.RenameColumn( name: "pronunciation", table: "flashcards", newName: "Pronunciation"); migrationBuilder.RenameColumn( name: "example", table: "flashcards", newName: "Example"); migrationBuilder.RenameColumn( name: "definition", table: "flashcards", newName: "Definition"); migrationBuilder.AddColumn( name: "study_session_id", table: "pronunciation_assessments", type: "TEXT", nullable: true); migrationBuilder.AlterColumn( name: "Definition", table: "flashcards", type: "TEXT", nullable: false, defaultValue: "", oldClrType: typeof(string), oldType: "TEXT", oldNullable: true); migrationBuilder.AddColumn( name: "FilledQuestionText", table: "flashcards", type: "TEXT", maxLength: 1000, nullable: true); migrationBuilder.AddColumn( name: "LastQuestionType", table: "flashcards", type: "TEXT", maxLength: 50, nullable: true); migrationBuilder.AddColumn( name: "Repetitions", table: "flashcards", type: "INTEGER", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "ReviewHistory", table: "flashcards", type: "TEXT", nullable: true); migrationBuilder.AddColumn( name: "Synonyms", table: "flashcards", type: "TEXT", maxLength: 2000, nullable: true); migrationBuilder.AddColumn( name: "easiness_factor", table: "flashcards", type: "REAL", nullable: false, defaultValue: 0f); migrationBuilder.AddColumn( name: "interval_days", table: "flashcards", type: "INTEGER", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "last_reviewed_at", table: "flashcards", type: "TEXT", nullable: true); migrationBuilder.AddColumn( name: "mastery_level", table: "flashcards", type: "INTEGER", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "next_review_date", table: "flashcards", type: "TEXT", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "times_correct", table: "flashcards", type: "INTEGER", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "times_reviewed", table: "flashcards", type: "INTEGER", nullable: false, defaultValue: 0); migrationBuilder.CreateTable( name: "study_sessions", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), user_id = table.Column(type: "TEXT", nullable: false), average_response_time_ms = table.Column(type: "INTEGER", nullable: false), CompletedCards = table.Column(type: "INTEGER", nullable: false), CompletedTests = table.Column(type: "INTEGER", nullable: false), correct_count = table.Column(type: "INTEGER", nullable: false), CurrentCardIndex = table.Column(type: "INTEGER", nullable: false), CurrentTestType = table.Column(type: "TEXT", maxLength: 50, nullable: true), duration_seconds = table.Column(type: "INTEGER", nullable: false), ended_at = table.Column(type: "TEXT", nullable: true), session_type = table.Column(type: "TEXT", maxLength: 50, nullable: false), started_at = table.Column(type: "TEXT", nullable: false), Status = table.Column(type: "INTEGER", nullable: false), total_cards = table.Column(type: "INTEGER", nullable: false), TotalTests = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { table.PrimaryKey("PK_study_sessions", x => x.Id); table.ForeignKey( name: "FK_study_sessions_user_profiles_user_id", column: x => x.user_id, principalTable: "user_profiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "study_cards", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), FlashcardId = table.Column(type: "TEXT", nullable: false), StudySessionId = table.Column(type: "TEXT", nullable: false), CompletedAt = table.Column(type: "TEXT", nullable: true), IsCompleted = table.Column(type: "INTEGER", nullable: false), Order = table.Column(type: "INTEGER", nullable: false), PlannedTests = table.Column(type: "TEXT", nullable: false), PlannedTestsJson = table.Column(type: "TEXT", nullable: false), StartedAt = table.Column(type: "TEXT", nullable: false), Word = table.Column(type: "TEXT", maxLength: 100, nullable: false) }, constraints: table => { table.PrimaryKey("PK_study_cards", x => x.Id); table.ForeignKey( name: "FK_study_cards_flashcards_FlashcardId", column: x => x.FlashcardId, principalTable: "flashcards", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_study_cards_study_sessions_StudySessionId", column: x => x.StudySessionId, principalTable: "study_sessions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "study_records", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), flashcard_id = table.Column(type: "TEXT", nullable: false), session_id = table.Column(type: "TEXT", nullable: false), user_id = table.Column(type: "TEXT", nullable: false), is_correct = table.Column(type: "INTEGER", nullable: false), NewEasinessFactor = table.Column(type: "REAL", nullable: false), NewIntervalDays = table.Column(type: "INTEGER", nullable: false), NewRepetitions = table.Column(type: "INTEGER", nullable: false), NextReviewDate = table.Column(type: "TEXT", nullable: false), PreviousEasinessFactor = table.Column(type: "REAL", nullable: false), PreviousIntervalDays = table.Column(type: "INTEGER", nullable: false), PreviousRepetitions = table.Column(type: "INTEGER", nullable: false), quality_rating = table.Column(type: "INTEGER", nullable: false), response_time_ms = table.Column(type: "INTEGER", nullable: true), studied_at = table.Column(type: "TEXT", nullable: false), study_mode = table.Column(type: "TEXT", maxLength: 50, nullable: false), user_answer = table.Column(type: "TEXT", nullable: true) }, constraints: table => { table.PrimaryKey("PK_study_records", x => x.Id); table.ForeignKey( name: "FK_study_records_flashcards_flashcard_id", column: x => x.flashcard_id, principalTable: "flashcards", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_study_records_study_sessions_session_id", column: x => x.session_id, principalTable: "study_sessions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_study_records_user_profiles_user_id", column: x => x.user_id, principalTable: "user_profiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "test_results", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), StudyCardId = table.Column(type: "TEXT", nullable: false), CompletedAt = table.Column(type: "TEXT", nullable: false), ConfidenceLevel = table.Column(type: "INTEGER", nullable: true), IsCorrect = table.Column(type: "INTEGER", nullable: false), ResponseTimeMs = table.Column(type: "INTEGER", nullable: false), TestType = table.Column(type: "TEXT", maxLength: 50, nullable: false), UserAnswer = table.Column(type: "TEXT", nullable: true) }, constraints: table => { table.PrimaryKey("PK_test_results", x => x.Id); table.ForeignKey( name: "FK_test_results_study_cards_StudyCardId", column: x => x.StudyCardId, principalTable: "study_cards", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_PronunciationAssessment_Session", table: "pronunciation_assessments", column: "study_session_id"); migrationBuilder.CreateIndex( name: "IX_study_cards_FlashcardId", table: "study_cards", column: "FlashcardId"); migrationBuilder.CreateIndex( name: "IX_study_cards_StudySessionId", table: "study_cards", column: "StudySessionId"); migrationBuilder.CreateIndex( name: "IX_study_records_flashcard_id", table: "study_records", column: "flashcard_id"); migrationBuilder.CreateIndex( name: "IX_study_records_session_id", table: "study_records", column: "session_id"); migrationBuilder.CreateIndex( name: "IX_StudyRecord_UserCard_TestType_Unique", table: "study_records", columns: new[] { "user_id", "flashcard_id", "study_mode" }, unique: true); migrationBuilder.CreateIndex( name: "IX_study_sessions_user_id", table: "study_sessions", column: "user_id"); migrationBuilder.CreateIndex( name: "IX_test_results_StudyCardId", table: "test_results", column: "StudyCardId"); migrationBuilder.AddForeignKey( name: "FK_pronunciation_assessments_study_sessions_study_session_id", table: "pronunciation_assessments", column: "study_session_id", principalTable: "study_sessions", principalColumn: "Id", onDelete: ReferentialAction.SetNull); } } }