mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 07:13:12 +00:00
* feat(vendors): add company roster management * fix(security): remove request-controlled write guards * fix(vendors): synchronize roster company fields * fix(vendors): source facets from companies
67 lines
2 KiB
C#
67 lines
2 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Data.SeaHavenIndustries.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class SH198_VendorCompanyNotesAndRowVersion : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "Notes",
|
|
table: "VendorCompanies",
|
|
type: "nvarchar(max)",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<byte[]>(
|
|
name: "RowVersion",
|
|
table: "VendorCompanies",
|
|
type: "rowversion",
|
|
rowVersion: true,
|
|
nullable: true);
|
|
|
|
// Backfill VendorCompany.Notes (vendor-directory source) deterministically
|
|
// from the most recently modified then highest-id nonempty Vendor.Notes.
|
|
// Vendor.Notes is retained separately for work-order editor compatibility;
|
|
// roster/directory paths read VendorCompany.Notes.
|
|
migrationBuilder.Sql(@"
|
|
;WITH SourceNotes AS (
|
|
SELECT
|
|
v.[CompanyId],
|
|
v.[Notes],
|
|
ROW_NUMBER() OVER (
|
|
PARTITION BY v.[CompanyId]
|
|
ORDER BY
|
|
v.[LastModificationTime] DESC,
|
|
v.[Id] DESC
|
|
) AS [RowNumber]
|
|
FROM [Vendors] v
|
|
WHERE v.[CompanyId] IS NOT NULL
|
|
AND v.[Notes] IS NOT NULL
|
|
AND LTRIM(RTRIM(v.[Notes])) <> ''
|
|
)
|
|
UPDATE vc
|
|
SET vc.[Notes] = src.[Notes]
|
|
FROM [VendorCompanies] vc
|
|
INNER JOIN SourceNotes src
|
|
ON src.[CompanyId] = vc.[Id]
|
|
WHERE src.[RowNumber] = 1;
|
|
");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropColumn(
|
|
name: "Notes",
|
|
table: "VendorCompanies");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "RowVersion",
|
|
table: "VendorCompanies");
|
|
}
|
|
}
|
|
}
|