|
| 1 | +using System; |
| 2 | +using Microsoft.EntityFrameworkCore.Migrations; |
| 3 | +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
| 4 | + |
| 5 | +namespace DataLayer.BookApp.Migrations |
| 6 | +{ |
| 7 | + public partial class Initial : Migration |
| 8 | + { |
| 9 | + protected override void Up(MigrationBuilder migrationBuilder) |
| 10 | + { |
| 11 | + migrationBuilder.CreateTable( |
| 12 | + name: "Authors", |
| 13 | + columns: table => new |
| 14 | + { |
| 15 | + AuthorId = table.Column<int>(type: "integer", nullable: false) |
| 16 | + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| 17 | + Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false) |
| 18 | + }, |
| 19 | + constraints: table => |
| 20 | + { |
| 21 | + table.PrimaryKey("PK_Authors", x => x.AuthorId); |
| 22 | + }); |
| 23 | + |
| 24 | + migrationBuilder.CreateTable( |
| 25 | + name: "Books", |
| 26 | + columns: table => new |
| 27 | + { |
| 28 | + BookId = table.Column<int>(type: "integer", nullable: false) |
| 29 | + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| 30 | + Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false), |
| 31 | + Description = table.Column<string>(type: "text", nullable: true), |
| 32 | + PublishedOn = table.Column<DateTime>(type: "date", nullable: false), |
| 33 | + Publisher = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true), |
| 34 | + Price = table.Column<decimal>(type: "numeric(9,2)", nullable: false), |
| 35 | + ImageUrl = table.Column<string>(type: "character varying(512)", unicode: false, maxLength: 512, nullable: true), |
| 36 | + SoftDeleted = table.Column<bool>(type: "boolean", nullable: false) |
| 37 | + }, |
| 38 | + constraints: table => |
| 39 | + { |
| 40 | + table.PrimaryKey("PK_Books", x => x.BookId); |
| 41 | + }); |
| 42 | + |
| 43 | + migrationBuilder.CreateTable( |
| 44 | + name: "BookAuthor", |
| 45 | + columns: table => new |
| 46 | + { |
| 47 | + BookId = table.Column<int>(type: "integer", nullable: false), |
| 48 | + AuthorId = table.Column<int>(type: "integer", nullable: false), |
| 49 | + Order = table.Column<byte>(type: "smallint", nullable: false) |
| 50 | + }, |
| 51 | + constraints: table => |
| 52 | + { |
| 53 | + table.PrimaryKey("PK_BookAuthor", x => new { x.BookId, x.AuthorId }); |
| 54 | + table.ForeignKey( |
| 55 | + name: "FK_BookAuthor_Authors_AuthorId", |
| 56 | + column: x => x.AuthorId, |
| 57 | + principalTable: "Authors", |
| 58 | + principalColumn: "AuthorId", |
| 59 | + onDelete: ReferentialAction.Cascade); |
| 60 | + table.ForeignKey( |
| 61 | + name: "FK_BookAuthor_Books_BookId", |
| 62 | + column: x => x.BookId, |
| 63 | + principalTable: "Books", |
| 64 | + principalColumn: "BookId", |
| 65 | + onDelete: ReferentialAction.Cascade); |
| 66 | + }); |
| 67 | + |
| 68 | + migrationBuilder.CreateTable( |
| 69 | + name: "PriceOffers", |
| 70 | + columns: table => new |
| 71 | + { |
| 72 | + PriceOfferId = table.Column<int>(type: "integer", nullable: false) |
| 73 | + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| 74 | + NewPrice = table.Column<decimal>(type: "numeric(9,2)", nullable: false), |
| 75 | + PromotionalText = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false), |
| 76 | + BookId = table.Column<int>(type: "integer", nullable: false) |
| 77 | + }, |
| 78 | + constraints: table => |
| 79 | + { |
| 80 | + table.PrimaryKey("PK_PriceOffers", x => x.PriceOfferId); |
| 81 | + table.ForeignKey( |
| 82 | + name: "FK_PriceOffers_Books_BookId", |
| 83 | + column: x => x.BookId, |
| 84 | + principalTable: "Books", |
| 85 | + principalColumn: "BookId", |
| 86 | + onDelete: ReferentialAction.Cascade); |
| 87 | + }); |
| 88 | + |
| 89 | + migrationBuilder.CreateTable( |
| 90 | + name: "Review", |
| 91 | + columns: table => new |
| 92 | + { |
| 93 | + ReviewId = table.Column<int>(type: "integer", nullable: false) |
| 94 | + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| 95 | + VoterName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true), |
| 96 | + NumStars = table.Column<int>(type: "integer", nullable: false), |
| 97 | + Comment = table.Column<string>(type: "text", nullable: true), |
| 98 | + BookId = table.Column<int>(type: "integer", nullable: false) |
| 99 | + }, |
| 100 | + constraints: table => |
| 101 | + { |
| 102 | + table.PrimaryKey("PK_Review", x => x.ReviewId); |
| 103 | + table.ForeignKey( |
| 104 | + name: "FK_Review_Books_BookId", |
| 105 | + column: x => x.BookId, |
| 106 | + principalTable: "Books", |
| 107 | + principalColumn: "BookId", |
| 108 | + onDelete: ReferentialAction.Cascade); |
| 109 | + }); |
| 110 | + |
| 111 | + migrationBuilder.CreateIndex( |
| 112 | + name: "IX_BookAuthor_AuthorId", |
| 113 | + table: "BookAuthor", |
| 114 | + column: "AuthorId"); |
| 115 | + |
| 116 | + migrationBuilder.CreateIndex( |
| 117 | + name: "IX_Books_PublishedOn", |
| 118 | + table: "Books", |
| 119 | + column: "PublishedOn"); |
| 120 | + |
| 121 | + migrationBuilder.CreateIndex( |
| 122 | + name: "IX_PriceOffers_BookId", |
| 123 | + table: "PriceOffers", |
| 124 | + column: "BookId", |
| 125 | + unique: true); |
| 126 | + |
| 127 | + migrationBuilder.CreateIndex( |
| 128 | + name: "IX_Review_BookId", |
| 129 | + table: "Review", |
| 130 | + column: "BookId"); |
| 131 | + } |
| 132 | + |
| 133 | + protected override void Down(MigrationBuilder migrationBuilder) |
| 134 | + { |
| 135 | + migrationBuilder.DropTable( |
| 136 | + name: "BookAuthor"); |
| 137 | + |
| 138 | + migrationBuilder.DropTable( |
| 139 | + name: "PriceOffers"); |
| 140 | + |
| 141 | + migrationBuilder.DropTable( |
| 142 | + name: "Review"); |
| 143 | + |
| 144 | + migrationBuilder.DropTable( |
| 145 | + name: "Authors"); |
| 146 | + |
| 147 | + migrationBuilder.DropTable( |
| 148 | + name: "Books"); |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments