feat: Add Free Issue Lines to ShopPOItems and InvoiceItems
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Distribution.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddFreeIssueLines : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "FK_SchemeId",
|
||||
table: "ShopPOItems",
|
||||
type: "char(36)",
|
||||
nullable: true,
|
||||
collation: "ascii_general_ci");
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsFree",
|
||||
table: "ShopPOItems",
|
||||
type: "tinyint(1)",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "SchemeName",
|
||||
table: "ShopPOItems",
|
||||
type: "longtext",
|
||||
nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "FK_SchemeId",
|
||||
table: "InvoiceItems",
|
||||
type: "char(36)",
|
||||
nullable: true,
|
||||
collation: "ascii_general_ci");
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsFree",
|
||||
table: "InvoiceItems",
|
||||
type: "tinyint(1)",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "SchemeName",
|
||||
table: "InvoiceItems",
|
||||
type: "longtext",
|
||||
nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
// Existing free-issue lines were plain zero-priced lines; flag them from their scheme redemption.
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ShopPOItems i
|
||||
JOIN SchemeRedemptions r ON r.FK_ShopPOId = i.FK_ShopPOId AND r.FK_FreeItemId = i.FK_ItemId
|
||||
JOIN Schemes s ON s.Id = r.FK_SchemeId
|
||||
SET i.IsFree = 1, i.FK_SchemeId = r.FK_SchemeId, i.SchemeName = s.Name
|
||||
WHERE i.UnitPrice = 0 AND i.IsActive = 1;");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE InvoiceItems ii
|
||||
JOIN ShopPOItems pi ON ii.FK_ShopPOItemId = pi.Id
|
||||
SET ii.IsFree = pi.IsFree, ii.FK_SchemeId = pi.FK_SchemeId, ii.SchemeName = pi.SchemeName
|
||||
WHERE pi.IsFree = 1;");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "FK_SchemeId",
|
||||
table: "ShopPOItems");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsFree",
|
||||
table: "ShopPOItems");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "SchemeName",
|
||||
table: "ShopPOItems");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "FK_SchemeId",
|
||||
table: "InvoiceItems");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsFree",
|
||||
table: "InvoiceItems");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "SchemeName",
|
||||
table: "InvoiceItems");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user