mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 08:23:12 +00:00
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Data.SeaHavenIndustries.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class SH187_WorkOrderServiceLink : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "ServiceId",
|
|
table: "workOrders",
|
|
type: "int",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "ServiceNameSnapshot",
|
|
table: "workOrders",
|
|
type: "nvarchar(200)",
|
|
maxLength: 200,
|
|
nullable: true);
|
|
|
|
migrationBuilder.Sql(
|
|
"""
|
|
UPDATE w
|
|
SET
|
|
w.[ServiceNameSnapshot] = LEFT(COALESCE(NULLIF(LTRIM(RTRIM(w.[Trade])), N''), NULLIF(LTRIM(RTRIM(w.[Problem])), N'')), 200),
|
|
w.[ServiceId] = s.[Id]
|
|
FROM [workOrders] w
|
|
LEFT JOIN [Services] s
|
|
ON (s.[IsDeleted] <> 1 OR s.[IsDeleted] IS NULL)
|
|
AND s.[NormalizedName] = LOWER(LTRIM(RTRIM(COALESCE(NULLIF(LTRIM(RTRIM(w.[Trade])), N''), NULLIF(LTRIM(RTRIM(w.[Problem])), N'')))))
|
|
WHERE w.[ServiceNameSnapshot] IS NULL;
|
|
""");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_workOrders_ServiceId",
|
|
table: "workOrders",
|
|
column: "ServiceId");
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "FK_workOrders_Services_ServiceId",
|
|
table: "workOrders",
|
|
column: "ServiceId",
|
|
principalTable: "Services",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropForeignKey(
|
|
name: "FK_workOrders_Services_ServiceId",
|
|
table: "workOrders");
|
|
|
|
migrationBuilder.DropIndex(
|
|
name: "IX_workOrders_ServiceId",
|
|
table: "workOrders");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "ServiceId",
|
|
table: "workOrders");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "ServiceNameSnapshot",
|
|
table: "workOrders");
|
|
}
|
|
}
|
|
}
|