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;"); } }