using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace SushiBarDatabaseImplement.Migrations { /// public partial class Initial : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Cooks", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Fio = table.Column(type: "text", nullable: false), EmploymentDate = table.Column(type: "timestamp without time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Cooks", x => x.Id); }); migrationBuilder.CreateTable( name: "Customers", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Fio = table.Column(type: "text", nullable: false), BirthdayDate = table.Column(type: "timestamp without time zone", nullable: true), SumOfAllOrders = table.Column(type: "double precision", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Customers", x => x.Id); }); migrationBuilder.CreateTable( name: "Dishes", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), DishName = table.Column(type: "text", nullable: false), Category = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Dishes", x => x.Id); }); migrationBuilder.CreateTable( name: "Ingredients", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), IngredientName = table.Column(type: "text", nullable: false), Unit = table.Column(type: "text", nullable: false), Cost = table.Column(type: "double precision", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Ingredients", x => x.Id); }); migrationBuilder.CreateTable( name: "Promotions", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), PromotionName = table.Column(type: "text", nullable: false), Discount = table.Column(type: "real", nullable: false), TriggeringSum = table.Column(type: "double precision", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Promotions", x => x.Id); }); migrationBuilder.CreateTable( name: "DishIngredients", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), DishId = table.Column(type: "integer", nullable: false), IngredientId = table.Column(type: "integer", nullable: false), Count = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DishIngredients", x => x.Id); table.ForeignKey( name: "FK_DishIngredients_Dishes_DishId", column: x => x.DishId, principalTable: "Dishes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_DishIngredients_Ingredients_IngredientId", column: x => x.IngredientId, principalTable: "Ingredients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Cheques", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CustomerId = table.Column(type: "integer", nullable: true), OrderDate = table.Column(type: "timestamp without time zone", nullable: false), TotalSum = table.Column(type: "double precision", nullable: false), PromotionId = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Cheques", x => x.Id); table.ForeignKey( name: "FK_Cheques_Customers_CustomerId", column: x => x.CustomerId, principalTable: "Customers", principalColumn: "Id"); table.ForeignKey( name: "FK_Cheques_Promotions_PromotionId", column: x => x.PromotionId, principalTable: "Promotions", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "ChequeItems", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ChequeId = table.Column(type: "integer", nullable: false), DishId = table.Column(type: "integer", nullable: false), CookId = table.Column(type: "integer", nullable: false), Count = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ChequeItems", x => x.Id); table.ForeignKey( name: "FK_ChequeItems_Cheques_ChequeId", column: x => x.ChequeId, principalTable: "Cheques", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ChequeItems_Cooks_CookId", column: x => x.CookId, principalTable: "Cooks", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ChequeItems_Dishes_DishId", column: x => x.DishId, principalTable: "Dishes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_ChequeItems_ChequeId", table: "ChequeItems", column: "ChequeId"); migrationBuilder.CreateIndex( name: "IX_ChequeItems_CookId", table: "ChequeItems", column: "CookId"); migrationBuilder.CreateIndex( name: "IX_ChequeItems_DishId", table: "ChequeItems", column: "DishId"); migrationBuilder.CreateIndex( name: "IX_Cheques_CustomerId", table: "Cheques", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_Cheques_PromotionId", table: "Cheques", column: "PromotionId"); migrationBuilder.CreateIndex( name: "IX_DishIngredients_DishId", table: "DishIngredients", column: "DishId"); migrationBuilder.CreateIndex( name: "IX_DishIngredients_IngredientId", table: "DishIngredients", column: "IngredientId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "ChequeItems"); migrationBuilder.DropTable( name: "DishIngredients"); migrationBuilder.DropTable( name: "Cheques"); migrationBuilder.DropTable( name: "Cooks"); migrationBuilder.DropTable( name: "Dishes"); migrationBuilder.DropTable( name: "Ingredients"); migrationBuilder.DropTable( name: "Customers"); migrationBuilder.DropTable( name: "Promotions"); } } }