183 lines
7.2 KiB
C#
183 lines
7.2 KiB
C#
|
using System;
|
|||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|||
|
|
|||
|
#nullable disable
|
|||
|
|
|||
|
namespace BookShopDataBaseImplement.Migrations
|
|||
|
{
|
|||
|
/// <inheritdoc />
|
|||
|
public partial class InitialCreate : Migration
|
|||
|
{
|
|||
|
/// <inheritdoc />
|
|||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|||
|
{
|
|||
|
migrationBuilder.CreateTable(
|
|||
|
name: "Authors",
|
|||
|
columns: table => new
|
|||
|
{
|
|||
|
Id = table.Column<int>(type: "int", nullable: false)
|
|||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|||
|
AuthorSurname = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|||
|
AuthorName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|||
|
AuthorPatronymic = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
|||
|
},
|
|||
|
constraints: table =>
|
|||
|
{
|
|||
|
table.PrimaryKey("PK_Authors", x => x.Id);
|
|||
|
});
|
|||
|
|
|||
|
migrationBuilder.CreateTable(
|
|||
|
name: "Clients",
|
|||
|
columns: table => new
|
|||
|
{
|
|||
|
Id = table.Column<int>(type: "int", nullable: false)
|
|||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|||
|
ClientSurname = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|||
|
ClientName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|||
|
ClientPatronymic = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|||
|
Email = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
|||
|
},
|
|||
|
constraints: table =>
|
|||
|
{
|
|||
|
table.PrimaryKey("PK_Clients", x => x.Id);
|
|||
|
});
|
|||
|
|
|||
|
migrationBuilder.CreateTable(
|
|||
|
name: "Genres",
|
|||
|
columns: table => new
|
|||
|
{
|
|||
|
Id = table.Column<int>(type: "int", nullable: false)
|
|||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|||
|
GenreName = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
|||
|
},
|
|||
|
constraints: table =>
|
|||
|
{
|
|||
|
table.PrimaryKey("PK_Genres", x => x.Id);
|
|||
|
});
|
|||
|
|
|||
|
migrationBuilder.CreateTable(
|
|||
|
name: "Books",
|
|||
|
columns: table => new
|
|||
|
{
|
|||
|
Id = table.Column<int>(type: "int", nullable: false)
|
|||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|||
|
BookName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|||
|
Cost = table.Column<double>(type: "float", nullable: false),
|
|||
|
GenreId = table.Column<int>(type: "int", nullable: false)
|
|||
|
},
|
|||
|
constraints: table =>
|
|||
|
{
|
|||
|
table.PrimaryKey("PK_Books", x => x.Id);
|
|||
|
table.ForeignKey(
|
|||
|
name: "FK_Books_Genres_GenreId",
|
|||
|
column: x => x.GenreId,
|
|||
|
principalTable: "Genres",
|
|||
|
principalColumn: "Id",
|
|||
|
onDelete: ReferentialAction.Cascade);
|
|||
|
});
|
|||
|
|
|||
|
migrationBuilder.CreateTable(
|
|||
|
name: "BookAuthors",
|
|||
|
columns: table => new
|
|||
|
{
|
|||
|
Id = table.Column<int>(type: "int", nullable: false)
|
|||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|||
|
BookId = table.Column<int>(type: "int", nullable: false),
|
|||
|
AuthorId = table.Column<int>(type: "int", nullable: false)
|
|||
|
},
|
|||
|
constraints: table =>
|
|||
|
{
|
|||
|
table.PrimaryKey("PK_BookAuthors", x => x.Id);
|
|||
|
table.ForeignKey(
|
|||
|
name: "FK_BookAuthors_Authors_AuthorId",
|
|||
|
column: x => x.AuthorId,
|
|||
|
principalTable: "Authors",
|
|||
|
principalColumn: "Id",
|
|||
|
onDelete: ReferentialAction.Cascade);
|
|||
|
table.ForeignKey(
|
|||
|
name: "FK_BookAuthors_Books_BookId",
|
|||
|
column: x => x.BookId,
|
|||
|
principalTable: "Books",
|
|||
|
principalColumn: "Id",
|
|||
|
onDelete: ReferentialAction.Cascade);
|
|||
|
});
|
|||
|
|
|||
|
migrationBuilder.CreateTable(
|
|||
|
name: "Orders",
|
|||
|
columns: table => new
|
|||
|
{
|
|||
|
Id = table.Column<int>(type: "int", nullable: false)
|
|||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|||
|
BookId = table.Column<int>(type: "int", nullable: false),
|
|||
|
ClientId = table.Column<int>(type: "int", nullable: false),
|
|||
|
Count = table.Column<int>(type: "int", nullable: false),
|
|||
|
Sum = table.Column<double>(type: "float", nullable: false),
|
|||
|
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false)
|
|||
|
},
|
|||
|
constraints: table =>
|
|||
|
{
|
|||
|
table.PrimaryKey("PK_Orders", x => x.Id);
|
|||
|
table.ForeignKey(
|
|||
|
name: "FK_Orders_Books_BookId",
|
|||
|
column: x => x.BookId,
|
|||
|
principalTable: "Books",
|
|||
|
principalColumn: "Id",
|
|||
|
onDelete: ReferentialAction.Cascade);
|
|||
|
table.ForeignKey(
|
|||
|
name: "FK_Orders_Clients_ClientId",
|
|||
|
column: x => x.ClientId,
|
|||
|
principalTable: "Clients",
|
|||
|
principalColumn: "Id",
|
|||
|
onDelete: ReferentialAction.Cascade);
|
|||
|
});
|
|||
|
|
|||
|
migrationBuilder.CreateIndex(
|
|||
|
name: "IX_BookAuthors_AuthorId",
|
|||
|
table: "BookAuthors",
|
|||
|
column: "AuthorId");
|
|||
|
|
|||
|
migrationBuilder.CreateIndex(
|
|||
|
name: "IX_BookAuthors_BookId",
|
|||
|
table: "BookAuthors",
|
|||
|
column: "BookId");
|
|||
|
|
|||
|
migrationBuilder.CreateIndex(
|
|||
|
name: "IX_Books_GenreId",
|
|||
|
table: "Books",
|
|||
|
column: "GenreId");
|
|||
|
|
|||
|
migrationBuilder.CreateIndex(
|
|||
|
name: "IX_Orders_BookId",
|
|||
|
table: "Orders",
|
|||
|
column: "BookId");
|
|||
|
|
|||
|
migrationBuilder.CreateIndex(
|
|||
|
name: "IX_Orders_ClientId",
|
|||
|
table: "Orders",
|
|||
|
column: "ClientId");
|
|||
|
}
|
|||
|
|
|||
|
/// <inheritdoc />
|
|||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|||
|
{
|
|||
|
migrationBuilder.DropTable(
|
|||
|
name: "BookAuthors");
|
|||
|
|
|||
|
migrationBuilder.DropTable(
|
|||
|
name: "Orders");
|
|||
|
|
|||
|
migrationBuilder.DropTable(
|
|||
|
name: "Authors");
|
|||
|
|
|||
|
migrationBuilder.DropTable(
|
|||
|
name: "Books");
|
|||
|
|
|||
|
migrationBuilder.DropTable(
|
|||
|
name: "Clients");
|
|||
|
|
|||
|
migrationBuilder.DropTable(
|
|||
|
name: "Genres");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|