WMSlite/WmsLite.Api/Database/migrations/0005_InboundOrderLineReceiveFields.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

66 lines
2.0 KiB
C#

using FluentMigrator;
namespace WmsLite.Api.Database.Migrations;
[Migration(5, "Inbound order line: received qty, line status, nullable location")]
public class InboundOrderLineReceiveFields0005 : Migration
{
public override void Up()
{
UpInventoryStyleLineTable("inbound_order_line");
UpInventoryStyleLineTable("outbound_order_line");
UpInventoryStyleLineTable("stocktake_order_line");
}
public override void Down()
{
DownInventoryStyleLineTable("inbound_order_line");
DownInventoryStyleLineTable("outbound_order_line");
DownInventoryStyleLineTable("stocktake_order_line");
}
private void UpInventoryStyleLineTable(string table)
{
if (!Schema.Table(table).Exists())
{
return;
}
if (!Schema.Table(table).Column("received_qty").Exists())
{
Alter.Table(table)
.AddColumn("received_qty").AsDecimal().NotNullable().WithDefaultValue(0);
}
if (!Schema.Table(table).Column("line_status").Exists())
{
// OrderLineStatus: Open = 1 (outbound/stocktake unused paths keep default)
Alter.Table(table)
.AddColumn("line_status").AsInt32().NotNullable().WithDefaultValue(1);
}
Execute.Sql($"ALTER TABLE {table} ALTER COLUMN location_code DROP NOT NULL;");
}
private void DownInventoryStyleLineTable(string table)
{
if (!Schema.Table(table).Exists())
{
return;
}
if (Schema.Table(table).Column("line_status").Exists())
{
Delete.Column("line_status").FromTable(table);
}
if (Schema.Table(table).Column("received_qty").Exists())
{
Delete.Column("received_qty").FromTable(table);
}
Execute.Sql($"UPDATE {table} SET location_code = '' WHERE location_code IS NULL;");
Execute.Sql($"ALTER TABLE {table} ALTER COLUMN location_code SET NOT NULL;");
}
}