mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 08:23:12 +00:00
Use IF EXISTS / IF COL_LENGTH guards and explicit EF migration metadata so partial environments can apply Phase 6 safely.
88 lines
3.3 KiB
C#
88 lines
3.3 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Data.SeaHavenIndustries.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
[DbContext(typeof(ApplicationDbContext))]
|
|
[Migration("20260625120000_Phase6_CompletionSlideOver")]
|
|
public partial class Phase6_CompletionSlideOver : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.Sql(@"
|
|
IF COL_LENGTH('workOrderAttachments', 'Category') IS NULL
|
|
BEGIN
|
|
ALTER TABLE workOrderAttachments ADD Category int NULL;
|
|
END
|
|
");
|
|
|
|
migrationBuilder.Sql(@"
|
|
IF OBJECT_ID(N'dbo.CompletionDocTemplates', N'U') IS NULL
|
|
BEGIN
|
|
CREATE TABLE CompletionDocTemplates (
|
|
Id int NOT NULL IDENTITY(1,1),
|
|
Name nvarchar(max) NOT NULL,
|
|
ServiceKey nvarchar(450) NOT NULL,
|
|
WorkOrderType int NULL,
|
|
TemplateUrl nvarchar(max) NOT NULL,
|
|
IsActive bit NOT NULL,
|
|
IsDeleted bit NULL,
|
|
createdby nvarchar(max) NULL,
|
|
DeleterUserId nvarchar(max) NULL,
|
|
DeletionTime datetime2 NULL,
|
|
CreatedDate datetime2 NULL,
|
|
LastModificationTime datetime2 NULL,
|
|
LastModifierUserId int NULL,
|
|
CONSTRAINT PK_CompletionDocTemplates PRIMARY KEY (Id)
|
|
);
|
|
END
|
|
");
|
|
|
|
migrationBuilder.Sql(@"
|
|
IF NOT EXISTS (
|
|
SELECT 1 FROM sys.indexes
|
|
WHERE name = N'IX_CompletionDocTemplates_ServiceKey_IsActive'
|
|
AND object_id = OBJECT_ID(N'dbo.CompletionDocTemplates'))
|
|
BEGIN
|
|
CREATE INDEX IX_CompletionDocTemplates_ServiceKey_IsActive
|
|
ON CompletionDocTemplates (ServiceKey, IsActive);
|
|
END
|
|
");
|
|
|
|
migrationBuilder.Sql(@"
|
|
UPDATE workOrders
|
|
SET DocStatus = 1
|
|
WHERE DocStatus IS NULL
|
|
AND SignOffAttachment IS NOT NULL
|
|
AND LTRIM(RTRIM(SignOffAttachment)) <> '';
|
|
");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.Sql(@"
|
|
UPDATE workOrders
|
|
SET DocStatus = NULL
|
|
WHERE DocStatus = 1
|
|
AND SignOffAttachment IS NOT NULL
|
|
AND LTRIM(RTRIM(SignOffAttachment)) <> '';
|
|
");
|
|
|
|
migrationBuilder.Sql(@"
|
|
IF OBJECT_ID(N'dbo.CompletionDocTemplates', N'U') IS NOT NULL
|
|
DROP TABLE CompletionDocTemplates;
|
|
");
|
|
|
|
migrationBuilder.Sql(@"
|
|
IF COL_LENGTH('workOrderAttachments', 'Category') IS NOT NULL
|
|
ALTER TABLE workOrderAttachments DROP COLUMN Category;
|
|
");
|
|
}
|
|
}
|
|
}
|