using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace backend.Migrations
{
///
public partial class InitialCreate : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "KhatmItems",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false),
Points = table.Column(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_KhatmItems", x => x.Id);
});
migrationBuilder.CreateTable(
name: "QuizQuestions",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
QuestionText = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false),
Option1 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false),
Option2 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false),
Option3 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false),
Option4 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false),
CorrectOption = table.Column(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_QuizQuestions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FullName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false),
Contact = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false),
TrackingCode = table.Column(type: "nvarchar(8)", maxLength: 8, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UserKhatmSelections",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column(type: "int", nullable: false),
KhatmItemId = table.Column(type: "int", nullable: false),
IsSelected = table.Column(type: "bit", nullable: false),
LastModified = table.Column(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserKhatmSelections", x => x.Id);
table.ForeignKey(
name: "FK_UserKhatmSelections_KhatmItems_KhatmItemId",
column: x => x.KhatmItemId,
principalTable: "KhatmItems",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_UserKhatmSelections_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "UserQuizAttempts",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column(type: "int", nullable: false),
ParticipationPoints = table.Column(type: "int", nullable: false),
CorrectAnswersCount = table.Column(type: "int", nullable: false),
TotalQuizPoints = table.Column(type: "int", nullable: false),
CompletedAt = table.Column(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserQuizAttempts", x => x.Id);
table.ForeignKey(
name: "FK_UserQuizAttempts_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "UserTotalScores",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column(type: "int", nullable: false),
TotalPoints = table.Column(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserTotalScores", x => x.Id);
table.ForeignKey(
name: "FK_UserTotalScores_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "UserQuizAnswers",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserQuizAttemptId = table.Column(type: "int", nullable: false),
QuestionId = table.Column(type: "int", nullable: false),
SelectedOption = table.Column(type: "int", nullable: false),
IsCorrect = table.Column(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserQuizAnswers", x => x.Id);
table.ForeignKey(
name: "FK_UserQuizAnswers_QuizQuestions_QuestionId",
column: x => x.QuestionId,
principalTable: "QuizQuestions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_UserQuizAnswers_UserQuizAttempts_UserQuizAttemptId",
column: x => x.UserQuizAttemptId,
principalTable: "UserQuizAttempts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "KhatmItems",
columns: new[] { "Id", "Points", "Title" },
values: new object[,]
{
{ 1, 5, "ختم نادعلی" },
{ 2, 10, "خطبه غدیر" },
{ 3, 7, "دعای توسل" }
});
migrationBuilder.InsertData(
table: "QuizQuestions",
columns: new[] { "Id", "CorrectOption", "Option1", "Option2", "Option3", "Option4", "QuestionText" },
values: new object[,]
{
{ 1, 1, "سال ۱۰ هجری", "سال ۱۱ هجری", "سال ۹ هجری", "سال ۱۲ هجری", "غدیر در چه سالی واقع شد؟" },
{ 2, 3, "ابوبکر", "عمر", "علی (ع)", "عثمان", "پیامبر اکرم (ص) در غدیر چه کسی را به عنوان جانشین معرفی کردند؟" },
{ 3, 2, "مسجد النبی", "غدیر خم", "مکه", "مدینه", "خطبه غدیر در کجا ایراد شد؟" }
});
migrationBuilder.CreateIndex(
name: "IX_UserKhatmSelections_KhatmItemId",
table: "UserKhatmSelections",
column: "KhatmItemId");
migrationBuilder.CreateIndex(
name: "IX_UserKhatmSelections_UserId_KhatmItemId",
table: "UserKhatmSelections",
columns: new[] { "UserId", "KhatmItemId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_UserQuizAnswers_QuestionId",
table: "UserQuizAnswers",
column: "QuestionId");
migrationBuilder.CreateIndex(
name: "IX_UserQuizAnswers_UserQuizAttemptId",
table: "UserQuizAnswers",
column: "UserQuizAttemptId");
migrationBuilder.CreateIndex(
name: "IX_UserQuizAttempts_UserId",
table: "UserQuizAttempts",
column: "UserId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Users_Contact",
table: "Users",
column: "Contact",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Users_TrackingCode",
table: "Users",
column: "TrackingCode",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_UserTotalScores_UserId",
table: "UserTotalScores",
column: "UserId",
unique: true);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UserKhatmSelections");
migrationBuilder.DropTable(
name: "UserQuizAnswers");
migrationBuilder.DropTable(
name: "UserTotalScores");
migrationBuilder.DropTable(
name: "KhatmItems");
migrationBuilder.DropTable(
name: "QuizQuestions");
migrationBuilder.DropTable(
name: "UserQuizAttempts");
migrationBuilder.DropTable(
name: "Users");
}
}
}