mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 04:53:11 +00:00
fix(migrations): make Phase6 completion slide-over migration idempotent
Use IF EXISTS / IF COL_LENGTH guards and explicit EF migration metadata so partial environments can apply Phase 6 safely.
This commit is contained in:
parent
2c26ead193
commit
3e2952f8a0
1 changed files with 49 additions and 38 deletions
|
|
@ -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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20260625120000_Phase6_CompletionSlideOver")]
|
||||
public partial class Phase6_CompletionSlideOver : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
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<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
ServiceKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
WorkOrderType = table.Column<int>(type: "int", nullable: true),
|
||||
TemplateUrl = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: true),
|
||||
createdby = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
DeleterUserId = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
CreatedDate = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
LastModifierUserId = table.Column<int>(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;
|
||||
");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue