WMSlite/WmsLite.Api/Database/migrations/0006_BackfillOrderLineQtyAndStatus.cs
zhougf fa1b286463 Add WmsLite monorepo with JWT auth, tenant context, and project READMEs.
Implement API security baseline (sys_user, JWT, audit fields, transactions,
unique constraints) and Web real login with 401 handling. Document setup
and development workflows in root, WmsLite.Api, and WmsLite.Web README files.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 14:17:47 +08:00

42 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using FluentMigrator;
namespace WmsLite.Api.Database.Migrations;
/// <summary>
/// 修复曾用 SqlSugar CodeFirst 加列但现有行为 NULL 的库(NOT NULL 约束失败)。
/// </summary>
[Migration(6, "Backfill order line received_qty / line_status nulls")]
public class BackfillOrderLineQtyAndStatus0006 : Migration
{
private static readonly string[] Tables = { "inbound_order_line", "outbound_order_line", "stocktake_order_line" };
public override void Up()
{
foreach (var table in Tables)
{
if (!Schema.Table(table).Exists())
{
continue;
}
if (Schema.Table(table).Column("received_qty").Exists())
{
Execute.Sql($"UPDATE {table} SET received_qty = 0 WHERE received_qty IS NULL;");
Execute.Sql($"ALTER TABLE {table} ALTER COLUMN received_qty SET DEFAULT 0;");
Execute.Sql($"ALTER TABLE {table} ALTER COLUMN received_qty SET NOT NULL;");
}
if (Schema.Table(table).Column("line_status").Exists())
{
Execute.Sql($"UPDATE {table} SET line_status = 1 WHERE line_status IS NULL;");
Execute.Sql($"ALTER TABLE {table} ALTER COLUMN line_status SET DEFAULT 1;");
Execute.Sql($"ALTER TABLE {table} ALTER COLUMN line_status SET NOT NULL;");
}
}
}
public override void Down()
{
}
}