study-lib-backend/Migrations/20201221192214_AddedAdminId.cs

134 lines
5.0 KiB
C#
Raw Normal View History

2020-12-21 23:31:53 +01:00
using Microsoft.EntityFrameworkCore.Migrations;
namespace StudyLib.Migrations
{
public partial class AddedAdminId : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "GroupID",
table: "Subjects",
type: "bigint",
nullable: true);
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
ID = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Year = table.Column<int>(type: "int", nullable: false),
AdminId = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.ID);
});
migrationBuilder.CreateTable(
name: "GroupCandidates",
columns: table => new
{
ID = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<string>(type: "nvarchar(450)", nullable: true),
GroupId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GroupCandidates", x => x.ID);
table.ForeignKey(
name: "FK_GroupCandidates_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_GroupCandidates_Groups_GroupId",
column: x => x.GroupId,
principalTable: "Groups",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GroupUser",
columns: table => new
{
GroupsID = table.Column<long>(type: "bigint", nullable: false),
UsersId = table.Column<string>(type: "nvarchar(450)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GroupUser", x => new { x.GroupsID, x.UsersId });
table.ForeignKey(
name: "FK_GroupUser_AspNetUsers_UsersId",
column: x => x.UsersId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GroupUser_Groups_GroupsID",
column: x => x.GroupsID,
principalTable: "Groups",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Subjects_GroupID",
table: "Subjects",
column: "GroupID");
migrationBuilder.CreateIndex(
name: "IX_GroupCandidates_GroupId",
table: "GroupCandidates",
column: "GroupId");
migrationBuilder.CreateIndex(
name: "IX_GroupCandidates_UserId",
table: "GroupCandidates",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_GroupUser_UsersId",
table: "GroupUser",
column: "UsersId");
migrationBuilder.AddForeignKey(
name: "FK_Subjects_Groups_GroupID",
table: "Subjects",
column: "GroupID",
principalTable: "Groups",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Subjects_Groups_GroupID",
table: "Subjects");
migrationBuilder.DropTable(
name: "GroupCandidates");
migrationBuilder.DropTable(
name: "GroupUser");
migrationBuilder.DropTable(
name: "Groups");
migrationBuilder.DropIndex(
name: "IX_Subjects_GroupID",
table: "Subjects");
migrationBuilder.DropColumn(
name: "GroupID",
table: "Subjects");
}
}
}