コード例 #1
0
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Courses_Students_StudentId",
                table: "Courses");

            migrationBuilder.DropForeignKey(
                name: "FK_Courses_Teachers_TeacherId",
                table: "Courses");

            migrationBuilder.DropTable(
                name: "AspNetRoleClaims");

            migrationBuilder.DropTable(
                name: "AspNetUserClaims");

            migrationBuilder.DropTable(
                name: "AspNetUserLogins");

            migrationBuilder.DropTable(
                name: "AspNetUserRoles");

            migrationBuilder.DropTable(
                name: "AspNetUserTokens");

            migrationBuilder.DropTable(
                name: "CourseAudits");

            migrationBuilder.DropTable(
                name: "Exams");

            migrationBuilder.DropTable(
                name: "TeacherAudits");

            migrationBuilder.DropTable(
                name: "AspNetRoles");

            migrationBuilder.DropTable(
                name: "AspNetUsers");

            migrationBuilder.DropTable(
                name: "Students");

            migrationBuilder.DropTable(
                name: "Teachers");

            migrationBuilder.DropTable(
                name: "Courses");

            SQLRegister.DropSQL(migrationBuilder);
        }
コード例 #2
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AspNetRoles",
                columns: table => new
            {
                Id               = table.Column <string>(type: "nvarchar(450)", nullable: false),
                Name             = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                NormalizedName   = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                ConcurrencyStamp = table.Column <string>(type: "nvarchar(max)", nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AspNetRoles", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "AspNetUsers",
                columns: table => new
            {
                Id                   = table.Column <string>(type: "nvarchar(450)", nullable: false),
                UserName             = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                NormalizedUserName   = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                Email                = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                NormalizedEmail      = table.Column <string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                EmailConfirmed       = table.Column <bool>(type: "bit", nullable: false),
                PasswordHash         = table.Column <string>(type: "nvarchar(max)", nullable: true),
                SecurityStamp        = table.Column <string>(type: "nvarchar(max)", nullable: true),
                ConcurrencyStamp     = table.Column <string>(type: "nvarchar(max)", nullable: true),
                PhoneNumber          = table.Column <string>(type: "nvarchar(max)", nullable: true),
                PhoneNumberConfirmed = table.Column <bool>(type: "bit", nullable: false),
                TwoFactorEnabled     = table.Column <bool>(type: "bit", nullable: false),
                LockoutEnd           = table.Column <DateTimeOffset>(type: "datetimeoffset", nullable: true),
                LockoutEnabled       = table.Column <bool>(type: "bit", nullable: false),
                AccessFailedCount    = table.Column <int>(type: "int", nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AspNetUsers", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "CourseAudits",
                columns: table => new
            {
                Id        = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                AuditData = table.Column <string>(type: "nvarchar(max)", nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_CourseAudits", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "Students",
                columns: table => new
            {
                Id             = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                FirstName      = table.Column <string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                LastName       = table.Column <string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                Email          = table.Column <string>(type: "nvarchar(max)", nullable: false),
                RegistrationNo = table.Column <string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
                PhoneNo        = table.Column <string>(type: "nvarchar(max)", nullable: true),
                CreatedAt      = table.Column <DateTime>(type: "datetime2", nullable: false),
                UpdatedAt      = table.Column <DateTime>(type: "datetime2", nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Students", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "TeacherAudits",
                columns: table => new
            {
                Id        = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                AuditData = table.Column <string>(type: "nvarchar(max)", nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_TeacherAudits", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "AspNetRoleClaims",
                columns: table => new
            {
                Id = table.Column <int>(type: "int", nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                RoleId     = table.Column <string>(type: "nvarchar(450)", nullable: false),
                ClaimType  = table.Column <string>(type: "nvarchar(max)", nullable: true),
                ClaimValue = table.Column <string>(type: "nvarchar(max)", nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
                table.ForeignKey(
                    name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
                    column: x => x.RoleId,
                    principalTable: "AspNetRoles",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AspNetUserClaims",
                columns: table => new
            {
                Id = table.Column <int>(type: "int", nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                UserId     = table.Column <string>(type: "nvarchar(450)", nullable: false),
                ClaimType  = table.Column <string>(type: "nvarchar(max)", nullable: true),
                ClaimValue = table.Column <string>(type: "nvarchar(max)", nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
                table.ForeignKey(
                    name: "FK_AspNetUserClaims_AspNetUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AspNetUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AspNetUserLogins",
                columns: table => new
            {
                LoginProvider       = table.Column <string>(type: "nvarchar(450)", nullable: false),
                ProviderKey         = table.Column <string>(type: "nvarchar(450)", nullable: false),
                ProviderDisplayName = table.Column <string>(type: "nvarchar(max)", nullable: true),
                UserId = table.Column <string>(type: "nvarchar(450)", nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
                table.ForeignKey(
                    name: "FK_AspNetUserLogins_AspNetUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AspNetUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AspNetUserRoles",
                columns: table => new
            {
                UserId = table.Column <string>(type: "nvarchar(450)", nullable: false),
                RoleId = table.Column <string>(type: "nvarchar(450)", nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
                table.ForeignKey(
                    name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
                    column: x => x.RoleId,
                    principalTable: "AspNetRoles",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
                table.ForeignKey(
                    name: "FK_AspNetUserRoles_AspNetUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AspNetUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AspNetUserTokens",
                columns: table => new
            {
                UserId        = table.Column <string>(type: "nvarchar(450)", nullable: false),
                LoginProvider = table.Column <string>(type: "nvarchar(450)", nullable: false),
                Name          = table.Column <string>(type: "nvarchar(450)", nullable: false),
                Value         = table.Column <string>(type: "nvarchar(max)", nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
                table.ForeignKey(
                    name: "FK_AspNetUserTokens_AspNetUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AspNetUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "Exams",
                columns: table => new
            {
                Id           = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                Title        = table.Column <string>(type: "nvarchar(250)", maxLength: 250, nullable: false),
                TotalMark    = table.Column <decimal>(type: "decimal(18,2)", nullable: false),
                ObtainedMark = table.Column <decimal>(type: "decimal(18,2)", nullable: false, defaultValue: 0m),
                CourseId     = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                TeacherId    = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                StudentId    = table.Column <Guid>(type: "uniqueidentifier", nullable: true),
                CreatedAt    = table.Column <DateTime>(type: "datetime2", nullable: false),
                UpdatedAt    = table.Column <DateTime>(type: "datetime2", nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Exams", x => x.Id);
                table.ForeignKey(
                    name: "FK_Exams_Students_StudentId",
                    column: x => x.StudentId,
                    principalTable: "Students",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "Teachers",
                columns: table => new
            {
                Id          = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                FirstName   = table.Column <string>(type: "nvarchar(max)", nullable: false),
                LastName    = table.Column <string>(type: "nvarchar(max)", nullable: false),
                Email       = table.Column <string>(type: "nvarchar(max)", nullable: false),
                PhoneNo     = table.Column <string>(type: "nvarchar(max)", nullable: false),
                Designation = table.Column <int>(type: "int", nullable: false),
                CourseId    = table.Column <Guid>(type: "uniqueidentifier", nullable: true),
                CreatedAt   = table.Column <DateTime>(type: "datetime2", nullable: false),
                UpdatedAt   = table.Column <DateTime>(type: "datetime2", nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Teachers", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "Courses",
                columns: table => new
            {
                Id        = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                Code      = table.Column <string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
                Title     = table.Column <string>(type: "nvarchar(250)", maxLength: 250, nullable: false),
                Credit    = table.Column <decimal>(type: "decimal(18,2)", nullable: false),
                TeacherId = table.Column <Guid>(type: "uniqueidentifier", nullable: false),
                StudentId = table.Column <Guid>(type: "uniqueidentifier", nullable: true),
                CreatedAt = table.Column <DateTime>(type: "datetime2", nullable: false),
                UpdatedAt = table.Column <DateTime>(type: "datetime2", nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Courses", x => x.Id);
                table.ForeignKey(
                    name: "FK_Courses_Students_StudentId",
                    column: x => x.StudentId,
                    principalTable: "Students",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_Courses_Teachers_TeacherId",
                    column: x => x.TeacherId,
                    principalTable: "Teachers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateIndex(
                name: "IX_AspNetRoleClaims_RoleId",
                table: "AspNetRoleClaims",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "RoleNameIndex",
                table: "AspNetRoles",
                column: "NormalizedName",
                unique: true,
                filter: "[NormalizedName] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_AspNetUserClaims_UserId",
                table: "AspNetUserClaims",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_AspNetUserLogins_UserId",
                table: "AspNetUserLogins",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_AspNetUserRoles_RoleId",
                table: "AspNetUserRoles",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "EmailIndex",
                table: "AspNetUsers",
                column: "NormalizedEmail");

            migrationBuilder.CreateIndex(
                name: "UserNameIndex",
                table: "AspNetUsers",
                column: "NormalizedUserName",
                unique: true,
                filter: "[NormalizedUserName] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_Courses_Id_TeacherId",
                table: "Courses",
                columns: new[] { "Id", "TeacherId" });

            migrationBuilder.CreateIndex(
                name: "IX_Courses_StudentId",
                table: "Courses",
                column: "StudentId");

            migrationBuilder.CreateIndex(
                name: "IX_Courses_TeacherId",
                table: "Courses",
                column: "TeacherId");

            migrationBuilder.CreateIndex(
                name: "IX_Exams_CourseId",
                table: "Exams",
                column: "CourseId");

            migrationBuilder.CreateIndex(
                name: "IX_Exams_Id",
                table: "Exams",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_Exams_StudentId",
                table: "Exams",
                column: "StudentId");

            migrationBuilder.CreateIndex(
                name: "IX_Exams_TeacherId",
                table: "Exams",
                column: "TeacherId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Students_Id",
                table: "Students",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_Teachers_CourseId",
                table: "Teachers",
                column: "CourseId");

            migrationBuilder.CreateIndex(
                name: "IX_Teachers_Id",
                table: "Teachers",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Exams_Courses_CourseId",
                table: "Exams",
                column: "CourseId",
                principalTable: "Courses",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Exams_Teachers_TeacherId",
                table: "Exams",
                column: "TeacherId",
                principalTable: "Teachers",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Teachers_Courses_CourseId",
                table: "Teachers",
                column: "CourseId",
                principalTable: "Courses",
                principalColumn: "Id");

            SQLRegister.RegisterSQL(migrationBuilder);
        }