using System; using Microsoft.EntityFrameworkCore.Migrations; namespace MultipleChoiceTrainer.Data.Migrations { public partial class BusinessEntities : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Categories", columns: table => new { Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(nullable: true), Description = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); }); migrationBuilder.CreateTable( name: "Sections", columns: table => new { Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(nullable: true), Description = table.Column(nullable: true), CategoryId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Sections", x => x.Id); table.ForeignKey( name: "FK_Sections_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Questions", columns: table => new { Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Text = table.Column(nullable: true), SectionId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Questions", x => x.Id); table.ForeignKey( name: "FK_Questions_Sections_SectionId", column: x => x.SectionId, principalTable: "Sections", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Answers", columns: table => new { Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Date = table.Column(nullable: false), QuestionId = table.Column(nullable: false), Successfull = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Answers", x => x.Id); table.ForeignKey( name: "FK_Answers_Questions_QuestionId", column: x => x.QuestionId, principalTable: "Questions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Choices", columns: table => new { Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), QuestionId = table.Column(nullable: false), Text = table.Column(nullable: true), IsTrue = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Choices", x => x.Id); table.ForeignKey( name: "FK_Choices_Questions_QuestionId", column: x => x.QuestionId, principalTable: "Questions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Answers_QuestionId", table: "Answers", column: "QuestionId"); migrationBuilder.CreateIndex( name: "IX_Choices_QuestionId", table: "Choices", column: "QuestionId"); migrationBuilder.CreateIndex( name: "IX_Questions_SectionId", table: "Questions", column: "SectionId"); migrationBuilder.CreateIndex( name: "IX_Sections_CategoryId", table: "Sections", column: "CategoryId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Answers"); migrationBuilder.DropTable( name: "Choices"); migrationBuilder.DropTable( name: "Questions"); migrationBuilder.DropTable( name: "Sections"); migrationBuilder.DropTable( name: "Categories"); } } }