fix: 修复套餐新增草稿默认值与开关落库
This commit is contained in:
@@ -81,7 +81,7 @@ public sealed class TenantPackage : AuditableEntityBase
|
||||
/// <summary>
|
||||
/// 发布状态(草稿/已发布)。
|
||||
/// </summary>
|
||||
public TenantPackagePublishStatus PublishStatus { get; set; } = TenantPackagePublishStatus.Published;
|
||||
public TenantPackagePublishStatus PublishStatus { get; set; } = TenantPackagePublishStatus.Draft;
|
||||
|
||||
/// <summary>
|
||||
/// 展示排序,数值越小越靠前。
|
||||
|
||||
@@ -677,9 +677,21 @@ public sealed class TakeoutAppDbContext(
|
||||
builder.Property(x => x.Name).HasMaxLength(128).IsRequired();
|
||||
builder.Property(x => x.Description).HasMaxLength(512);
|
||||
builder.Property(x => x.FeaturePoliciesJson).HasColumnType("text");
|
||||
builder.Property(x => x.PublishStatus).HasConversion<int>().HasDefaultValue(TenantPackagePublishStatus.Published).HasComment("发布状态:0=草稿,1=已发布。");
|
||||
builder.Property(x => x.IsPublicVisible).HasDefaultValue(true).HasComment("是否对外可见(展示页/套餐列表可见性)。");
|
||||
builder.Property(x => x.IsAllowNewTenantPurchase).HasDefaultValue(true).HasComment("是否允许新租户购买/选择(仅影响新购)。");
|
||||
builder.Property(x => x.PublishStatus)
|
||||
.HasConversion<int>()
|
||||
.HasDefaultValue(TenantPackagePublishStatus.Draft)
|
||||
.HasComment("发布状态:0=草稿,1=已发布。");
|
||||
|
||||
// 1. 解决 EF Core 默认值哨兵问题:当我们希望插入 false/0 时,若数据库配置了 default 且 EF 认为该值是“未设置”,会导致 insert 省略列,最终落库为默认值。
|
||||
// 2. (空行后) 将哨兵值设置为数据库默认值:true 作为哨兵,false 才会被显式写入,从而保证“可见性/可售开关”在新增时可正确落库。
|
||||
builder.Property(x => x.IsPublicVisible)
|
||||
.HasDefaultValue(true)
|
||||
.HasSentinel(true)
|
||||
.HasComment("是否对外可见(展示页/套餐列表可见性)。");
|
||||
builder.Property(x => x.IsAllowNewTenantPurchase)
|
||||
.HasDefaultValue(true)
|
||||
.HasSentinel(true)
|
||||
.HasComment("是否允许新租户购买/选择(仅影响新购)。");
|
||||
builder.Property(x => x.SortOrder).HasDefaultValue(0).HasComment("展示排序,数值越小越靠前。");
|
||||
builder.HasIndex(x => new { x.IsActive, x.SortOrder });
|
||||
builder.HasIndex(x => new { x.PublishStatus, x.IsActive, x.IsPublicVisible, x.IsAllowNewTenantPurchase, x.SortOrder });
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TakeoutSaaS.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ChangeTenantPackageDefaults : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "PublishStatus",
|
||||
table: "tenant_packages",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
comment: "发布状态:0=草稿,1=已发布。",
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer",
|
||||
oldDefaultValue: 1,
|
||||
oldComment: "发布状态:0=草稿,1=已发布。");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "PublishStatus",
|
||||
table: "tenant_packages",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 1,
|
||||
comment: "发布状态:0=草稿,1=已发布。",
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer",
|
||||
oldDefaultValue: 0,
|
||||
oldComment: "发布状态:0=草稿,1=已发布。");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6298,7 +6298,7 @@ namespace TakeoutSaaS.Infrastructure.Migrations
|
||||
b.Property<int>("PublishStatus")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasDefaultValue(0)
|
||||
.HasComment("发布状态:0=草稿,1=已发布。");
|
||||
|
||||
b.Property<int>("SortOrder")
|
||||
|
||||
Reference in New Issue
Block a user