240 lines
10 KiB
C#
Raw Normal View History

2024-05-15 21:14:04 +04:00
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace SushiBarDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Cooks",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Fio = table.Column<string>(type: "text", nullable: false),
EmploymentDate = table.Column<DateTime>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Fio = table.Column<string>(type: "text", nullable: false),
2024-05-15 21:15:39 +04:00
BirthdayDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
2024-05-15 21:14:04 +04:00
SumOfAllOrders = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Customers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Dishes",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DishName = table.Column<string>(type: "text", nullable: false),
Category = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Dishes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Ingredients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
IngredientName = table.Column<string>(type: "text", nullable: false),
Unit = table.Column<string>(type: "text", nullable: false),
Cost = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Ingredients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Promotions",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
PromotionName = table.Column<string>(type: "text", nullable: false),
Discount = table.Column<float>(type: "real", nullable: false),
TriggeringSum = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Promotions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DishIngredients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DishId = table.Column<int>(type: "integer", nullable: false),
IngredientId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CustomerId = table.Column<int>(type: "integer", nullable: true),
OrderDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
TotalSum = table.Column<double>(type: "double precision", nullable: false),
PromotionId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ChequeId = table.Column<int>(type: "integer", nullable: false),
DishId = table.Column<int>(type: "integer", nullable: false),
CookId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}