diff --git a/Data.SeaHavenIndustries/Migrations/20260625120000_Phase6_CompletionSlideOver.cs b/Data.SeaHavenIndustries/Migrations/20260625120000_Phase6_CompletionSlideOver.cs
index 08ff98d..f52940d 100644
--- a/Data.SeaHavenIndustries/Migrations/20260625120000_Phase6_CompletionSlideOver.cs
+++ b/Data.SeaHavenIndustries/Migrations/20260625120000_Phase6_CompletionSlideOver.cs
@@ -1,4 +1,5 @@
-using System;
+using Data.SeaHavenIndustries;
+using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@@ -6,45 +7,52 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.SeaHavenIndustries.Migrations
{
///
+ [DbContext(typeof(ApplicationDbContext))]
+ [Migration("20260625120000_Phase6_CompletionSlideOver")]
public partial class Phase6_CompletionSlideOver : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
- migrationBuilder.AddColumn(
- name: "Category",
- table: "workOrderAttachments",
- type: "int",
- nullable: true);
+ migrationBuilder.Sql(@"
+ IF COL_LENGTH('workOrderAttachments', 'Category') IS NULL
+ BEGIN
+ ALTER TABLE workOrderAttachments ADD Category int NULL;
+ END
+ ");
- migrationBuilder.CreateTable(
- name: "CompletionDocTemplates",
- columns: table => new
- {
- Id = table.Column(type: "int", nullable: false)
- .Annotation("SqlServer:Identity", "1, 1"),
- Name = table.Column(type: "nvarchar(max)", nullable: false),
- ServiceKey = table.Column(type: "nvarchar(450)", nullable: false),
- WorkOrderType = table.Column(type: "int", nullable: true),
- TemplateUrl = table.Column(type: "nvarchar(max)", nullable: false),
- IsActive = table.Column(type: "bit", nullable: false),
- IsDeleted = table.Column(type: "bit", nullable: true),
- createdby = table.Column(type: "nvarchar(max)", nullable: true),
- DeleterUserId = table.Column(type: "nvarchar(max)", nullable: true),
- DeletionTime = table.Column(type: "datetime2", nullable: true),
- CreatedDate = table.Column(type: "datetime2", nullable: true),
- LastModificationTime = table.Column(type: "datetime2", nullable: true),
- LastModifierUserId = table.Column(type: "int", nullable: true)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_CompletionDocTemplates", x => x.Id);
- });
+ 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.CreateIndex(
- name: "IX_CompletionDocTemplates_ServiceKey_IsActive",
- table: "CompletionDocTemplates",
- columns: new[] { "ServiceKey", "IsActive" });
+ 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
@@ -66,12 +74,15 @@ namespace Data.SeaHavenIndustries.Migrations
AND LTRIM(RTRIM(SignOffAttachment)) <> '';
");
- migrationBuilder.DropTable(
- name: "CompletionDocTemplates");
+ migrationBuilder.Sql(@"
+ IF OBJECT_ID(N'dbo.CompletionDocTemplates', N'U') IS NOT NULL
+ DROP TABLE CompletionDocTemplates;
+ ");
- migrationBuilder.DropColumn(
- name: "Category",
- table: "workOrderAttachments");
+ migrationBuilder.Sql(@"
+ IF COL_LENGTH('workOrderAttachments', 'Category') IS NOT NULL
+ ALTER TABLE workOrderAttachments DROP COLUMN Category;
+ ");
}
}
}