using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace TakeoutSaaS.Infrastructure.Migrations
{
///
public partial class AddProductComboGroups : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "product_combo_group_items",
columns: table => new
{
Id = table.Column(type: "bigint", nullable: false, comment: "实体唯一标识。")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ComboGroupId = table.Column(type: "bigint", nullable: false, comment: "所属套餐分组 ID。"),
ProductId = table.Column(type: "bigint", nullable: false, comment: "商品 ID。"),
Quantity = table.Column(type: "integer", nullable: false, comment: "数量。"),
SortOrder = table.Column(type: "integer", nullable: false, comment: "排序值。"),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "创建时间(UTC)。"),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间(UTC),从未更新时为 null。"),
DeletedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "软删除时间(UTC),未删除时为 null。"),
CreatedBy = table.Column(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"),
UpdatedBy = table.Column(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"),
DeletedBy = table.Column(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"),
TenantId = table.Column(type: "bigint", nullable: false, comment: "所属租户 ID。")
},
constraints: table =>
{
table.PrimaryKey("PK_product_combo_group_items", x => x.Id);
},
comment: "套餐分组内商品。");
migrationBuilder.CreateTable(
name: "product_combo_groups",
columns: table => new
{
Id = table.Column(type: "bigint", nullable: false, comment: "实体唯一标识。")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ProductId = table.Column(type: "bigint", nullable: false, comment: "套餐商品 ID。"),
Name = table.Column(type: "character varying(64)", maxLength: 64, nullable: false, comment: "分组名称。"),
MinSelect = table.Column(type: "integer", nullable: false, comment: "最小选择数。"),
MaxSelect = table.Column(type: "integer", nullable: false, comment: "最大选择数。"),
SortOrder = table.Column(type: "integer", nullable: false, comment: "排序值。"),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "创建时间(UTC)。"),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间(UTC),从未更新时为 null。"),
DeletedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "软删除时间(UTC),未删除时为 null。"),
CreatedBy = table.Column(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"),
UpdatedBy = table.Column(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"),
DeletedBy = table.Column(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"),
TenantId = table.Column(type: "bigint", nullable: false, comment: "所属租户 ID。")
},
constraints: table =>
{
table.PrimaryKey("PK_product_combo_groups", x => x.Id);
},
comment: "套餐分组。");
migrationBuilder.CreateIndex(
name: "IX_product_combo_group_items_TenantId_ComboGroupId_ProductId",
table: "product_combo_group_items",
columns: new[] { "TenantId", "ComboGroupId", "ProductId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_product_combo_group_items_TenantId_ComboGroupId_SortOrder",
table: "product_combo_group_items",
columns: new[] { "TenantId", "ComboGroupId", "SortOrder" });
migrationBuilder.CreateIndex(
name: "IX_product_combo_groups_TenantId_ProductId_Name",
table: "product_combo_groups",
columns: new[] { "TenantId", "ProductId", "Name" });
migrationBuilder.CreateIndex(
name: "IX_product_combo_groups_TenantId_ProductId_SortOrder",
table: "product_combo_groups",
columns: new[] { "TenantId", "ProductId", "SortOrder" });
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "product_combo_group_items");
migrationBuilder.DropTable(
name: "product_combo_groups");
}
}
}