PIbd-31_COP6/BookDatabaseImplement/Migrations/20241028084936_InitMig.cs

95 lines
3.7 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace BookDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitMig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Books",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: false),
BookType = table.Column<string>(type: "text", nullable: false),
Annotation = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Readers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Readers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Histories",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
BookId = table.Column<int>(type: "integer", nullable: false),
ReaderId = table.Column<int>(type: "integer", nullable: false),
DateBorrowed = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Histories", x => x.Id);
table.ForeignKey(
name: "FK_Histories_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Histories_Readers_ReaderId",
column: x => x.ReaderId,
principalTable: "Readers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Histories_BookId",
table: "Histories",
column: "BookId");
migrationBuilder.CreateIndex(
name: "IX_Histories_ReaderId",
table: "Histories",
column: "ReaderId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Histories");
migrationBuilder.DropTable(
name: "Books");
migrationBuilder.DropTable(
name: "Readers");
}
}
}