using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; namespace DataLayer.Migrations { public partial class Initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Categories", columns: table => new { CategoryId = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), AudibleCategoryId = table.Column(nullable: true), Name = table.Column(nullable: true), ParentCategoryCategoryId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.CategoryId); table.ForeignKey( name: "FK_Categories_Categories_ParentCategoryCategoryId", column: x => x.ParentCategoryCategoryId, principalTable: "Categories", principalColumn: "CategoryId", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Contributors", columns: table => new { ContributorId = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: true), AudibleAuthorId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Contributors", x => x.ContributorId); }); migrationBuilder.CreateTable( name: "Series", columns: table => new { SeriesId = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), AudibleSeriesId = table.Column(nullable: true), Name = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Series", x => x.SeriesId); }); migrationBuilder.CreateTable( name: "Books", columns: table => new { BookId = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), AudibleProductId = table.Column(nullable: true), Title = table.Column(nullable: true), Description = table.Column(nullable: true), LengthInMinutes = table.Column(nullable: false), PictureId = table.Column(nullable: true), HasBookDetails = table.Column(nullable: false), IsAbridged = table.Column(nullable: false), Publisher = table.Column(nullable: true), DatePublished = table.Column(nullable: true), CategoryId = table.Column(nullable: false), Rating_OverallRating = table.Column(nullable: false), Rating_PerformanceRating = table.Column(nullable: false), Rating_StoryRating = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Books", x => x.BookId); table.ForeignKey( name: "FK_Books_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "CategoryId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "BookContributor", columns: table => new { BookId = table.Column(nullable: false), ContributorId = table.Column(nullable: false), Role = table.Column(nullable: false), Order = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_BookContributor", x => new { x.BookId, x.ContributorId, x.Role }); table.ForeignKey( name: "FK_BookContributor_Books_BookId", column: x => x.BookId, principalTable: "Books", principalColumn: "BookId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_BookContributor_Contributors_ContributorId", column: x => x.ContributorId, principalTable: "Contributors", principalColumn: "ContributorId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Library", columns: table => new { BookId = table.Column(nullable: false), DateAdded = table.Column(nullable: false), DownloadBookLink = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Library", x => x.BookId); table.ForeignKey( name: "FK_Library_Books_BookId", column: x => x.BookId, principalTable: "Books", principalColumn: "BookId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "SeriesBook", columns: table => new { SeriesId = table.Column(nullable: false), BookId = table.Column(nullable: false), Index = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_SeriesBook", x => new { x.SeriesId, x.BookId }); table.ForeignKey( name: "FK_SeriesBook_Books_BookId", column: x => x.BookId, principalTable: "Books", principalColumn: "BookId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_SeriesBook_Series_SeriesId", column: x => x.SeriesId, principalTable: "Series", principalColumn: "SeriesId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Supplement", columns: table => new { SupplementId = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), BookId = table.Column(nullable: false), Url = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Supplement", x => x.SupplementId); table.ForeignKey( name: "FK_Supplement_Books_BookId", column: x => x.BookId, principalTable: "Books", principalColumn: "BookId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserDefinedItem", columns: table => new { BookId = table.Column(nullable: false), Tags = table.Column(nullable: true), Rating_OverallRating = table.Column(nullable: false), Rating_PerformanceRating = table.Column(nullable: false), Rating_StoryRating = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserDefinedItem", x => x.BookId); table.ForeignKey( name: "FK_UserDefinedItem_Books_BookId", column: x => x.BookId, principalTable: "Books", principalColumn: "BookId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_BookContributor_BookId", table: "BookContributor", column: "BookId"); migrationBuilder.CreateIndex( name: "IX_BookContributor_ContributorId", table: "BookContributor", column: "ContributorId"); migrationBuilder.CreateIndex( name: "IX_Books_AudibleProductId", table: "Books", column: "AudibleProductId"); migrationBuilder.CreateIndex( name: "IX_Books_CategoryId", table: "Books", column: "CategoryId"); migrationBuilder.CreateIndex( name: "IX_Categories_AudibleCategoryId", table: "Categories", column: "AudibleCategoryId"); migrationBuilder.CreateIndex( name: "IX_Categories_ParentCategoryCategoryId", table: "Categories", column: "ParentCategoryCategoryId"); migrationBuilder.CreateIndex( name: "IX_Contributors_Name", table: "Contributors", column: "Name"); migrationBuilder.CreateIndex( name: "IX_Series_AudibleSeriesId", table: "Series", column: "AudibleSeriesId"); migrationBuilder.CreateIndex( name: "IX_SeriesBook_BookId", table: "SeriesBook", column: "BookId"); migrationBuilder.CreateIndex( name: "IX_SeriesBook_SeriesId", table: "SeriesBook", column: "SeriesId"); migrationBuilder.CreateIndex( name: "IX_Supplement_BookId", table: "Supplement", column: "BookId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "BookContributor"); migrationBuilder.DropTable( name: "Library"); migrationBuilder.DropTable( name: "SeriesBook"); migrationBuilder.DropTable( name: "Supplement"); migrationBuilder.DropTable( name: "UserDefinedItem"); migrationBuilder.DropTable( name: "Contributors"); migrationBuilder.DropTable( name: "Series"); migrationBuilder.DropTable( name: "Books"); migrationBuilder.DropTable( name: "Categories"); } } }