using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TakeoutSaaS.Infrastructure.Migrations
{
    /// <summary>
    /// 为租户套餐新增排序字段与索引的迁移。
    /// </summary>
    /// <inheritdoc />
    public partial class AddTenantPackageSortOrder : Migration
    {
        /// <summary>
        /// 升级：新增排序列并创建索引。
        /// </summary>
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            // 1. 新增排序列，默认 0
            migrationBuilder.AddColumn<int>(
                name: "SortOrder",
                table: "tenant_packages",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                comment: "展示排序，数值越小越靠前。");

            // 2. 创建可售+排序索引用于前台查询
            migrationBuilder.CreateIndex(
                name: "IX_tenant_packages_IsActive_SortOrder",
                table: "tenant_packages",
                columns: new[] { "IsActive", "SortOrder" });
        }

        /// <summary>
        /// 回滚：删除索引并移除排序列。
        /// </summary>
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            // 1. 移除索引
            migrationBuilder.DropIndex(
                name: "IX_tenant_packages_IsActive_SortOrder",
                table: "tenant_packages");

            // 2. 回滚排序列
            migrationBuilder.DropColumn(
                name: "SortOrder",
                table: "tenant_packages");
        }
    }
}
