using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace ForumDatabaseImplement.Migrations { /// public partial class InitNew : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Categories", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CategoryName = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Nickname = table.Column(type: "nvarchar(max)", nullable: false), Password = table.Column(type: "nvarchar(max)", nullable: false), Email = table.Column(type: "nvarchar(max)", nullable: false), RegistrationDate = table.Column(type: "datetime2", nullable: false), ActivityDate = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Questions", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CreateDate = table.Column(type: "datetime2", nullable: false), UserId = table.Column(type: "int", nullable: false), CategoryId = table.Column(type: "int", nullable: false), Topic = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Questions", x => x.Id); table.ForeignKey( name: "FK_Questions_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "Id", onDelete: ReferentialAction.NoAction); table.ForeignKey( name: "FK_Questions_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Answers", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ResponseDate = table.Column(type: "datetime2", nullable: false), QuestionId = table.Column(type: "int", nullable: false), UserId = table.Column(type: "int", nullable: false), Comment = table.Column(type: "nvarchar(max)", 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.NoAction); table.ForeignKey( name: "FK_Answers_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Answers_QuestionId", table: "Answers", column: "QuestionId"); migrationBuilder.CreateIndex( name: "IX_Answers_UserId", table: "Answers", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Questions_CategoryId", table: "Questions", column: "CategoryId"); migrationBuilder.CreateIndex( name: "IX_Questions_UserId", table: "Questions", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Answers"); migrationBuilder.DropTable( name: "Questions"); migrationBuilder.DropTable( name: "Categories"); migrationBuilder.DropTable( name: "Users"); } } }