138 lines
5.5 KiB
C#
138 lines
5.5 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace ForumDatabaseImplement.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitNew : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Categories",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
CategoryName = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Categories", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Nickname = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
RegistrationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
ActivityDate = table.Column<DateTime>(type: "datetime2", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Questions",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
UserId = table.Column<int>(type: "int", nullable: false),
|
|
CategoryId = table.Column<int>(type: "int", nullable: false),
|
|
Topic = table.Column<string>(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<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
ResponseDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
QuestionId = table.Column<int>(type: "int", nullable: false),
|
|
UserId = table.Column<int>(type: "int", nullable: false),
|
|
Comment = table.Column<string>(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");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Answers");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Questions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Categories");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Users");
|
|
}
|
|
}
|
|
}
|