using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BookHive.Migrations
{
///
public partial class InitialDatabase : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Authors",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FirstName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false),
LastName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false),
Biography = table.Column(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
BirthDate = table.Column(type: "date", nullable: false),
Nationality = table.Column(type: "nvarchar(60)", maxLength: 60, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Authors", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Members",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Email = table.Column(type: "nvarchar(max)", nullable: false),
FirstName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false),
LastName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false),
MembershipDate = table.Column(type: "date", nullable: false),
IsActive = table.Column(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Members", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Books",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false),
Isbn = table.Column(type: "nvarchar(max)", nullable: false),
Summary = table.Column(type: "nvarchar(3000)", maxLength: 3000, nullable: true),
PageCount = table.Column(type: "int", nullable: false),
PublishedDate = table.Column(type: "date", nullable: false),
Genre = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false),
AuthorId = table.Column(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.Id);
table.ForeignKey(
name: "FK_Books_Authors_AuthorId",
column: x => x.AuthorId,
principalTable: "Authors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Loans",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
BookId = table.Column(type: "int", nullable: false),
MemberId = table.Column(type: "int", nullable: false),
LoanDate = table.Column(type: "date", nullable: false),
DueDate = table.Column(type: "date", nullable: false),
ReturnDate = table.Column(type: "date", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Loans", x => x.Id);
table.ForeignKey(
name: "FK_Loans_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Loans_Members_MemberId",
column: x => x.MemberId,
principalTable: "Members",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Reviews",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
BookId = table.Column(type: "int", nullable: false),
MemberId = table.Column(type: "int", nullable: false),
Rating = table.Column(type: "int", nullable: false),
Comment = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
CreatedAt = table.Column(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Reviews", x => x.Id);
table.ForeignKey(
name: "FK_Reviews_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Reviews_Members_MemberId",
column: x => x.MemberId,
principalTable: "Members",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Books_AuthorId",
table: "Books",
column: "AuthorId");
migrationBuilder.CreateIndex(
name: "IX_Loans_BookId",
table: "Loans",
column: "BookId");
migrationBuilder.CreateIndex(
name: "IX_Loans_MemberId",
table: "Loans",
column: "MemberId");
migrationBuilder.CreateIndex(
name: "IX_Reviews_BookId",
table: "Reviews",
column: "BookId");
migrationBuilder.CreateIndex(
name: "IX_Reviews_MemberId",
table: "Reviews",
column: "MemberId");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Loans");
migrationBuilder.DropTable(
name: "Reviews");
migrationBuilder.DropTable(
name: "Books");
migrationBuilder.DropTable(
name: "Members");
migrationBuilder.DropTable(
name: "Authors");
}
}
}