using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace BookShopDataBaseImplement.Migrations { /// public partial class InitialCreate : 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"), AuthorSurname = table.Column(type: "nvarchar(max)", nullable: false), AuthorName = table.Column(type: "nvarchar(max)", nullable: false), AuthorPatronymic = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Authors", x => x.Id); }); migrationBuilder.CreateTable( name: "Clients", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ClientSurname = table.Column(type: "nvarchar(max)", nullable: false), ClientName = table.Column(type: "nvarchar(max)", nullable: false), ClientPatronymic = table.Column(type: "nvarchar(max)", nullable: false), Email = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Clients", x => x.Id); }); migrationBuilder.CreateTable( name: "Genres", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), GenreName = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Genres", x => x.Id); }); migrationBuilder.CreateTable( name: "Books", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), BookName = table.Column(type: "nvarchar(max)", nullable: false), Cost = table.Column(type: "float", nullable: false), GenreId = table.Column(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(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), BookId = table.Column(type: "int", nullable: false), AuthorId = table.Column(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(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), BookId = table.Column(type: "int", nullable: false), ClientId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), DateCreate = table.Column(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"); } /// 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"); } } }