IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
    CREATE TABLE [__EFMigrationsHistory] (
        [MigrationId] nvarchar(150) NOT NULL,
        [ProductVersion] nvarchar(32) NOT NULL,
        CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
    );
END;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [AspNetRoles] (
        [Id] nvarchar(450) NOT NULL,
        [Name] nvarchar(256) NULL,
        [NormalizedName] nvarchar(256) NULL,
        [ConcurrencyStamp] nvarchar(max) NULL,
        CONSTRAINT [PK_AspNetRoles] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [AspNetUsers] (
        [Id] nvarchar(450) NOT NULL,
        [FirstName] nvarchar(max) NOT NULL,
        [LastName] nvarchar(max) NOT NULL,
        [EmployeeNumber] nvarchar(max) NULL,
        [DateOfBirth] datetime2 NULL,
        [HireDate] datetime2 NOT NULL,
        [TerminationDate] datetime2 NULL,
        [Address] nvarchar(max) NULL,
        [City] nvarchar(max) NULL,
        [State] nvarchar(max) NULL,
        [ZipCode] nvarchar(max) NULL,
        [Department] nvarchar(max) NULL,
        [Position] nvarchar(max) NULL,
        [HourlyRate] decimal(18,2) NOT NULL,
        [Theme] nvarchar(max) NULL,
        [DateFormat] nvarchar(max) NULL,
        [TimeZone] nvarchar(max) NULL,
        [DashboardLayout] int NULL,
        [IsActive] bit NOT NULL,
        [CanViewShopFloor] bit NOT NULL,
        [CanManageJobs] bit NOT NULL,
        [CanManageInventory] bit NOT NULL,
        [CanManageCustomers] bit NOT NULL,
        [CanCreateQuotes] bit NOT NULL,
        [CanApproveQuotes] bit NOT NULL,
        [ProfilePicturePath] nvarchar(max) NULL,
        [Notes] nvarchar(max) NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [LastLoginDate] datetime2 NULL,
        [UserName] nvarchar(256) NULL,
        [NormalizedUserName] nvarchar(256) NULL,
        [Email] nvarchar(256) NULL,
        [NormalizedEmail] nvarchar(256) NULL,
        [EmailConfirmed] bit NOT NULL,
        [PasswordHash] nvarchar(max) NULL,
        [SecurityStamp] nvarchar(max) NULL,
        [ConcurrencyStamp] nvarchar(max) NULL,
        [PhoneNumber] nvarchar(max) NULL,
        [PhoneNumberConfirmed] bit NOT NULL,
        [TwoFactorEnabled] bit NOT NULL,
        [LockoutEnd] datetimeoffset NULL,
        [LockoutEnabled] bit NOT NULL,
        [AccessFailedCount] int NOT NULL,
        CONSTRAINT [PK_AspNetUsers] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [Equipment] (
        [Id] int NOT NULL IDENTITY,
        [EquipmentName] nvarchar(max) NOT NULL,
        [EquipmentNumber] nvarchar(max) NULL,
        [EquipmentType] nvarchar(max) NOT NULL,
        [Manufacturer] nvarchar(max) NULL,
        [Model] nvarchar(max) NULL,
        [SerialNumber] nvarchar(max) NULL,
        [PurchaseDate] datetime2 NULL,
        [PurchasePrice] decimal(18,2) NOT NULL,
        [WarrantyExpiration] datetime2 NULL,
        [Status] int NOT NULL,
        [Location] nvarchar(max) NULL,
        [RecommendedMaintenanceIntervalDays] int NOT NULL,
        [LastMaintenanceDate] datetime2 NULL,
        [NextScheduledMaintenance] datetime2 NULL,
        [Notes] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Equipment] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [PricingTiers] (
        [Id] int NOT NULL IDENTITY,
        [TierName] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NULL,
        [DiscountPercent] decimal(18,2) NOT NULL,
        [IsActive] bit NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_PricingTiers] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [Suppliers] (
        [Id] int NOT NULL IDENTITY,
        [CompanyName] nvarchar(max) NOT NULL,
        [ContactName] nvarchar(max) NULL,
        [Email] nvarchar(max) NULL,
        [Phone] nvarchar(max) NULL,
        [Address] nvarchar(max) NULL,
        [City] nvarchar(max) NULL,
        [State] nvarchar(max) NULL,
        [ZipCode] nvarchar(max) NULL,
        [Country] nvarchar(max) NULL,
        [Website] nvarchar(max) NULL,
        [Notes] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Suppliers] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [AspNetRoleClaims] (
        [Id] int NOT NULL IDENTITY,
        [RoleId] nvarchar(450) NOT NULL,
        [ClaimType] nvarchar(max) NULL,
        [ClaimValue] nvarchar(max) NULL,
        CONSTRAINT [PK_AspNetRoleClaims] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_AspNetRoleClaims_AspNetRoles_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [AspNetRoles] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [AspNetUserClaims] (
        [Id] int NOT NULL IDENTITY,
        [UserId] nvarchar(450) NOT NULL,
        [ClaimType] nvarchar(max) NULL,
        [ClaimValue] nvarchar(max) NULL,
        CONSTRAINT [PK_AspNetUserClaims] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_AspNetUserClaims_AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [AspNetUsers] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [AspNetUserLogins] (
        [LoginProvider] nvarchar(450) NOT NULL,
        [ProviderKey] nvarchar(450) NOT NULL,
        [ProviderDisplayName] nvarchar(max) NULL,
        [UserId] nvarchar(450) NOT NULL,
        CONSTRAINT [PK_AspNetUserLogins] PRIMARY KEY ([LoginProvider], [ProviderKey]),
        CONSTRAINT [FK_AspNetUserLogins_AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [AspNetUsers] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [AspNetUserRoles] (
        [UserId] nvarchar(450) NOT NULL,
        [RoleId] nvarchar(450) NOT NULL,
        CONSTRAINT [PK_AspNetUserRoles] PRIMARY KEY ([UserId], [RoleId]),
        CONSTRAINT [FK_AspNetUserRoles_AspNetRoles_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [AspNetRoles] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_AspNetUserRoles_AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [AspNetUsers] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [AspNetUserTokens] (
        [UserId] nvarchar(450) NOT NULL,
        [LoginProvider] nvarchar(450) NOT NULL,
        [Name] nvarchar(450) NOT NULL,
        [Value] nvarchar(max) NULL,
        CONSTRAINT [PK_AspNetUserTokens] PRIMARY KEY ([UserId], [LoginProvider], [Name]),
        CONSTRAINT [FK_AspNetUserTokens_AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [AspNetUsers] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [MaintenanceRecords] (
        [Id] int NOT NULL IDENTITY,
        [EquipmentId] int NOT NULL,
        [MaintenanceType] nvarchar(max) NOT NULL,
        [Status] int NOT NULL,
        [Priority] int NOT NULL,
        [ScheduledDate] datetime2 NOT NULL,
        [CompletedDate] datetime2 NULL,
        [PerformedById] nvarchar(450) NULL,
        [Description] nvarchar(max) NOT NULL,
        [WorkPerformed] nvarchar(max) NULL,
        [PartsReplaced] nvarchar(max) NULL,
        [LaborCost] decimal(18,2) NOT NULL,
        [PartsCost] decimal(18,2) NOT NULL,
        [TotalCost] decimal(18,2) NOT NULL,
        [DowntimeHours] decimal(18,2) NOT NULL,
        [Notes] nvarchar(max) NULL,
        [TechnicianNotes] nvarchar(max) NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_MaintenanceRecords] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_MaintenanceRecords_AspNetUsers_PerformedById] FOREIGN KEY ([PerformedById]) REFERENCES [AspNetUsers] ([Id]) ON DELETE SET NULL,
        CONSTRAINT [FK_MaintenanceRecords_Equipment_EquipmentId] FOREIGN KEY ([EquipmentId]) REFERENCES [Equipment] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [Customers] (
        [Id] int NOT NULL IDENTITY,
        [CompanyName] nvarchar(450) NOT NULL,
        [ContactFirstName] nvarchar(max) NULL,
        [ContactLastName] nvarchar(max) NULL,
        [Email] nvarchar(450) NOT NULL,
        [Phone] nvarchar(max) NULL,
        [MobilePhone] nvarchar(max) NULL,
        [Address] nvarchar(max) NULL,
        [City] nvarchar(max) NULL,
        [State] nvarchar(max) NULL,
        [ZipCode] nvarchar(max) NULL,
        [Country] nvarchar(max) NULL,
        [IsCommercial] bit NOT NULL,
        [TaxId] nvarchar(max) NULL,
        [CreditLimit] decimal(18,2) NOT NULL,
        [CurrentBalance] decimal(18,2) NOT NULL,
        [PaymentTerms] nvarchar(max) NULL,
        [PricingTierId] int NULL,
        [GeneralNotes] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [LastContactDate] datetime2 NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Customers] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Customers_PricingTiers_PricingTierId] FOREIGN KEY ([PricingTierId]) REFERENCES [PricingTiers] ([Id]) ON DELETE SET NULL
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [InventoryItems] (
        [Id] int NOT NULL IDENTITY,
        [SKU] nvarchar(450) NOT NULL,
        [Name] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NULL,
        [Category] nvarchar(max) NOT NULL,
        [ColorName] nvarchar(max) NULL,
        [ColorCode] nvarchar(max) NULL,
        [Finish] nvarchar(max) NULL,
        [Manufacturer] nvarchar(max) NULL,
        [ManufacturerPartNumber] nvarchar(max) NULL,
        [QuantityOnHand] decimal(18,2) NOT NULL,
        [UnitOfMeasure] nvarchar(max) NOT NULL,
        [ReorderPoint] decimal(18,2) NOT NULL,
        [ReorderQuantity] decimal(18,2) NOT NULL,
        [MinimumStock] decimal(18,2) NOT NULL,
        [MaximumStock] decimal(18,2) NOT NULL,
        [UnitCost] decimal(18,2) NOT NULL,
        [AverageCost] decimal(18,2) NOT NULL,
        [LastPurchasePrice] decimal(18,2) NOT NULL,
        [LastPurchaseDate] datetime2 NULL,
        [PrimarySupplierId] int NULL,
        [SupplierPartNumber] nvarchar(max) NULL,
        [Location] nvarchar(max) NULL,
        [Notes] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [DiscontinuedDate] datetime2 NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_InventoryItems] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_InventoryItems_Suppliers_PrimarySupplierId] FOREIGN KEY ([PrimarySupplierId]) REFERENCES [Suppliers] ([Id]) ON DELETE SET NULL
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [CustomerNotes] (
        [Id] int NOT NULL IDENTITY,
        [CustomerId] int NOT NULL,
        [Note] nvarchar(max) NOT NULL,
        [IsImportant] bit NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_CustomerNotes] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_CustomerNotes_Customers_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [Customers] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [Quotes] (
        [Id] int NOT NULL IDENTITY,
        [QuoteNumber] nvarchar(450) NOT NULL,
        [CustomerId] int NOT NULL,
        [PreparedById] nvarchar(450) NULL,
        [Status] int NOT NULL,
        [IsCommercial] bit NOT NULL,
        [QuoteDate] datetime2 NOT NULL,
        [ExpirationDate] datetime2 NULL,
        [SentDate] datetime2 NULL,
        [ApprovedDate] datetime2 NULL,
        [SubTotal] decimal(18,2) NOT NULL,
        [DiscountPercent] decimal(18,2) NOT NULL,
        [DiscountAmount] decimal(18,2) NOT NULL,
        [TaxPercent] decimal(18,2) NOT NULL,
        [TaxAmount] decimal(18,2) NOT NULL,
        [Total] decimal(18,2) NOT NULL,
        [Description] nvarchar(max) NULL,
        [Terms] nvarchar(max) NULL,
        [Notes] nvarchar(max) NULL,
        [CustomerPO] nvarchar(max) NULL,
        [AISuggestedPrice] decimal(18,2) NULL,
        [AIPriceRationale] nvarchar(max) NULL,
        [UsedAISuggestion] bit NOT NULL,
        [ConvertedToJobId] int NULL,
        [ConvertedDate] datetime2 NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Quotes] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Quotes_AspNetUsers_PreparedById] FOREIGN KEY ([PreparedById]) REFERENCES [AspNetUsers] ([Id]) ON DELETE SET NULL,
        CONSTRAINT [FK_Quotes_Customers_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [Customers] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [InventoryTransactions] (
        [Id] int NOT NULL IDENTITY,
        [InventoryItemId] int NOT NULL,
        [TransactionType] int NOT NULL,
        [Quantity] decimal(18,2) NOT NULL,
        [UnitCost] decimal(18,2) NOT NULL,
        [TotalCost] decimal(18,2) NOT NULL,
        [TransactionDate] datetime2 NOT NULL,
        [Reference] nvarchar(max) NULL,
        [Notes] nvarchar(max) NULL,
        [BalanceAfter] decimal(18,2) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_InventoryTransactions] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_InventoryTransactions_InventoryItems_InventoryItemId] FOREIGN KEY ([InventoryItemId]) REFERENCES [InventoryItems] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [Jobs] (
        [Id] int NOT NULL IDENTITY,
        [JobNumber] nvarchar(450) NOT NULL,
        [CustomerId] int NOT NULL,
        [QuoteId] int NULL,
        [AssignedEmployeeId] nvarchar(450) NULL,
        [Description] nvarchar(max) NOT NULL,
        [Status] int NOT NULL,
        [Priority] int NOT NULL,
        [ScheduledDate] datetime2 NULL,
        [StartedDate] datetime2 NULL,
        [CompletedDate] datetime2 NULL,
        [DueDate] datetime2 NULL,
        [EstimatedCost] decimal(18,2) NOT NULL,
        [ActualCost] decimal(18,2) NOT NULL,
        [QuotedPrice] decimal(18,2) NOT NULL,
        [FinalPrice] decimal(18,2) NOT NULL,
        [CustomerPO] nvarchar(max) NULL,
        [SpecialInstructions] nvarchar(max) NULL,
        [RequiresCustomerApproval] bit NOT NULL,
        [IsCustomerApproved] bit NOT NULL,
        [CustomerApprovedDate] datetime2 NULL,
        [EstimatedHours] int NOT NULL,
        [ActualHours] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Jobs] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Jobs_AspNetUsers_AssignedEmployeeId] FOREIGN KEY ([AssignedEmployeeId]) REFERENCES [AspNetUsers] ([Id]) ON DELETE SET NULL,
        CONSTRAINT [FK_Jobs_Customers_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [Customers] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_Jobs_Quotes_QuoteId] FOREIGN KEY ([QuoteId]) REFERENCES [Quotes] ([Id]) ON DELETE SET NULL
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [QuoteItems] (
        [Id] int NOT NULL IDENTITY,
        [QuoteId] int NOT NULL,
        [Description] nvarchar(max) NOT NULL,
        [Quantity] int NOT NULL,
        [ColorName] nvarchar(max) NULL,
        [ColorCode] nvarchar(max) NULL,
        [Finish] nvarchar(max) NULL,
        [Length] decimal(18,2) NULL,
        [Width] decimal(18,2) NULL,
        [Height] decimal(18,2) NULL,
        [SurfaceArea] decimal(18,2) NULL,
        [MeasurementUnit] nvarchar(max) NULL,
        [UnitPrice] decimal(18,2) NOT NULL,
        [TotalPrice] decimal(18,2) NOT NULL,
        [RequiresSandblasting] bit NOT NULL,
        [RequiresMasking] bit NOT NULL,
        [EstimatedMinutes] int NOT NULL,
        [Notes] nvarchar(max) NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_QuoteItems] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_QuoteItems_Quotes_QuoteId] FOREIGN KEY ([QuoteId]) REFERENCES [Quotes] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [JobItems] (
        [Id] int NOT NULL IDENTITY,
        [JobId] int NOT NULL,
        [Description] nvarchar(max) NOT NULL,
        [Quantity] int NOT NULL,
        [PowderInventoryId] int NULL,
        [ColorName] nvarchar(max) NULL,
        [ColorCode] nvarchar(max) NULL,
        [Finish] nvarchar(max) NULL,
        [Length] decimal(18,2) NULL,
        [Width] decimal(18,2) NULL,
        [Height] decimal(18,2) NULL,
        [Weight] decimal(18,2) NULL,
        [SurfaceArea] decimal(18,2) NULL,
        [MeasurementUnit] nvarchar(max) NULL,
        [UnitPrice] decimal(18,2) NOT NULL,
        [TotalPrice] decimal(18,2) NOT NULL,
        [MaterialCost] decimal(18,2) NOT NULL,
        [LaborCost] decimal(18,2) NOT NULL,
        [RequiresSandblasting] bit NOT NULL,
        [RequiresMasking] bit NOT NULL,
        [EstimatedMinutes] int NOT NULL,
        [ActualMinutes] int NOT NULL,
        [Notes] nvarchar(max) NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobItems] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobItems_InventoryItems_PowderInventoryId] FOREIGN KEY ([PowderInventoryId]) REFERENCES [InventoryItems] ([Id]),
        CONSTRAINT [FK_JobItems_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [JobNotes] (
        [Id] int NOT NULL IDENTITY,
        [JobId] int NOT NULL,
        [Note] nvarchar(max) NOT NULL,
        [IsImportant] bit NOT NULL,
        [IsInternal] bit NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobNotes] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobNotes_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [JobPhotos] (
        [Id] int NOT NULL IDENTITY,
        [JobId] int NOT NULL,
        [FileName] nvarchar(max) NOT NULL,
        [FilePath] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NULL,
        [PhotoType] nvarchar(max) NOT NULL,
        [PhotoDate] datetime2 NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobPhotos] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobPhotos_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE TABLE [JobStatusHistory] (
        [Id] int NOT NULL IDENTITY,
        [JobId] int NOT NULL,
        [FromStatus] int NOT NULL,
        [ToStatus] int NOT NULL,
        [ChangedDate] datetime2 NOT NULL,
        [Notes] nvarchar(max) NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobStatusHistory] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobStatusHistory_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'CreatedAt', N'CreatedBy', N'DeletedAt', N'DeletedBy', N'Description', N'DiscountPercent', N'IsActive', N'IsDeleted', N'TierName', N'UpdatedAt', N'UpdatedBy') AND [object_id] = OBJECT_ID(N'[PricingTiers]'))
        SET IDENTITY_INSERT [PricingTiers] ON;
    EXEC(N'INSERT INTO [PricingTiers] ([Id], [CreatedAt], [CreatedBy], [DeletedAt], [DeletedBy], [Description], [DiscountPercent], [IsActive], [IsDeleted], [TierName], [UpdatedAt], [UpdatedBy])
    VALUES (1, ''2026-02-05T16:37:50.1751418Z'', NULL, NULL, NULL, N''Standard pricing for regular customers'', 0.0, CAST(1 AS bit), CAST(0 AS bit), N''Standard'', NULL, NULL),
    (2, ''2026-02-05T16:37:50.1751424Z'', NULL, NULL, NULL, N''5% discount for preferred customers'', 5.0, CAST(1 AS bit), CAST(0 AS bit), N''Preferred'', NULL, NULL),
    (3, ''2026-02-05T16:37:50.1751426Z'', NULL, NULL, NULL, N''10% discount for premium customers'', 10.0, CAST(1 AS bit), CAST(0 AS bit), N''Premium'', NULL, NULL)');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'CreatedAt', N'CreatedBy', N'DeletedAt', N'DeletedBy', N'Description', N'DiscountPercent', N'IsActive', N'IsDeleted', N'TierName', N'UpdatedAt', N'UpdatedBy') AND [object_id] = OBJECT_ID(N'[PricingTiers]'))
        SET IDENTITY_INSERT [PricingTiers] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_AspNetRoleClaims_RoleId] ON [AspNetRoleClaims] ([RoleId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [RoleNameIndex] ON [AspNetRoles] ([NormalizedName]) WHERE [NormalizedName] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_AspNetUserClaims_UserId] ON [AspNetUserClaims] ([UserId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_AspNetUserLogins_UserId] ON [AspNetUserLogins] ([UserId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_AspNetUserRoles_RoleId] ON [AspNetUserRoles] ([RoleId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [EmailIndex] ON [AspNetUsers] ([NormalizedEmail]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [UserNameIndex] ON [AspNetUsers] ([NormalizedUserName]) WHERE [NormalizedUserName] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_CustomerNotes_CustomerId] ON [CustomerNotes] ([CustomerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_Customers_CompanyName] ON [Customers] ([CompanyName]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Customers_Email] ON [Customers] ([Email]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_Customers_PricingTierId] ON [Customers] ([PricingTierId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_InventoryItems_PrimarySupplierId] ON [InventoryItems] ([PrimarySupplierId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE UNIQUE INDEX [IX_InventoryItems_SKU] ON [InventoryItems] ([SKU]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_InventoryTransactions_InventoryItemId] ON [InventoryTransactions] ([InventoryItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_JobItems_JobId] ON [JobItems] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_JobItems_PowderInventoryId] ON [JobItems] ([PowderInventoryId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_JobNotes_JobId] ON [JobNotes] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_JobPhotos_JobId] ON [JobPhotos] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_Jobs_AssignedEmployeeId] ON [Jobs] ([AssignedEmployeeId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_Jobs_CustomerId] ON [Jobs] ([CustomerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Jobs_JobNumber] ON [Jobs] ([JobNumber]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_Jobs_QuoteId] ON [Jobs] ([QuoteId]) WHERE [QuoteId] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_JobStatusHistory_JobId] ON [JobStatusHistory] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_MaintenanceRecords_EquipmentId] ON [MaintenanceRecords] ([EquipmentId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_MaintenanceRecords_PerformedById] ON [MaintenanceRecords] ([PerformedById]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_QuoteItems_QuoteId] ON [QuoteItems] ([QuoteId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_Quotes_CustomerId] ON [Quotes] ([CustomerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE INDEX [IX_Quotes_PreparedById] ON [Quotes] ([PreparedById]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Quotes_QuoteNumber] ON [Quotes] ([QuoteNumber]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260205163837_InitialCreate'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260205163837_InitialCreate', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE TABLE [Companies] (
        [Id] int NOT NULL IDENTITY,
        [CompanyName] nvarchar(max) NOT NULL,
        [CompanyCode] nvarchar(450) NULL,
        [PrimaryContactName] nvarchar(max) NOT NULL,
        [PrimaryContactEmail] nvarchar(max) NOT NULL,
        [Phone] nvarchar(max) NULL,
        [Address] nvarchar(max) NULL,
        [City] nvarchar(max) NULL,
        [State] nvarchar(max) NULL,
        [ZipCode] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [SubscriptionStartDate] datetime2 NOT NULL,
        [SubscriptionEndDate] datetime2 NULL,
        [SubscriptionPlan] nvarchar(max) NULL,
        [TimeZone] nvarchar(max) NULL,
        [LogoPath] nvarchar(max) NULL,
        [Settings] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Companies] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_Companies_CompanyCode] ON [Companies] ([CompanyCode]) WHERE [CompanyCode] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN

                    SET IDENTITY_INSERT Companies ON;
                    INSERT INTO Companies (Id, CompanyName, CompanyCode, PrimaryContactName, PrimaryContactEmail, Phone, Address, City, State, ZipCode, IsActive, SubscriptionStartDate, SubscriptionPlan, TimeZone, CompanyId, CreatedAt, IsDeleted)
                    VALUES (1, 'Demo Company', 'DEMO', 'Admin User', 'admin@demo.com', '(555) 123-4567', '123 Demo Street', 'Demo City', 'CA', '90210', 1, GETUTCDATE(), 'Enterprise', 'America/New_York', 1, GETUTCDATE(), 0);
                    SET IDENTITY_INSERT Companies OFF;
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Quotes] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [PricingTiers] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [JobStatusHistory] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Jobs] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [JobPhotos] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [JobNotes] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [JobItems] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [InventoryTransactions] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Equipment] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Customers] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [CustomerNotes] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CompanyId] int NOT NULL DEFAULT 1;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CompanyRole] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CompanyId] = 1, [CreatedAt] = ''2026-02-06T01:20:42.5015235Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CompanyId] = 1, [CreatedAt] = ''2026-02-06T01:20:42.5015242Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CompanyId] = 1, [CreatedAt] = ''2026-02-06T01:20:42.5015243Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE INDEX [IX_Suppliers_CompanyId] ON [Suppliers] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE INDEX [IX_Quotes_CompanyId] ON [Quotes] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE INDEX [IX_PricingTiers_CompanyId] ON [PricingTiers] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE INDEX [IX_Jobs_CompanyId] ON [Jobs] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE INDEX [IX_InventoryItems_CompanyId] ON [InventoryItems] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE INDEX [IX_Equipment_CompanyId] ON [Equipment] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE INDEX [IX_Customers_CompanyId] ON [Customers] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    CREATE INDEX [IX_AspNetUsers_CompanyId] ON [AspNetUsers] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD CONSTRAINT [FK_AspNetUsers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Customers] ADD CONSTRAINT [FK_Customers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Equipment] ADD CONSTRAINT [FK_Equipment_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD CONSTRAINT [FK_InventoryItems_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [PricingTiers] ADD CONSTRAINT [FK_PricingTiers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Quotes] ADD CONSTRAINT [FK_Quotes_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    ALTER TABLE [Suppliers] ADD CONSTRAINT [FK_Suppliers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206012125_AddMultiTenancy'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260206012125_AddMultiTenancy', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206150138_MakeCompanyNameOptional'
)
BEGIN
    DECLARE @var0 sysname;
    SELECT @var0 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'CompanyName');
    IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + '];');
    ALTER TABLE [Customers] ALTER COLUMN [CompanyName] nvarchar(450) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206150138_MakeCompanyNameOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T15:00:38.8151700Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206150138_MakeCompanyNameOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T15:00:38.8151704Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206150138_MakeCompanyNameOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T15:00:38.8151706Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206150138_MakeCompanyNameOptional'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260206150138_MakeCompanyNameOptional', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206174417_AddCompanyOperatingCosts'
)
BEGIN
    CREATE TABLE [CompanyOperatingCosts] (
        [Id] int NOT NULL IDENTITY,
        [CompanyId] int NOT NULL,
        [StandardLaborRate] decimal(18,2) NOT NULL,
        [OvertimeLaborRate] decimal(18,2) NOT NULL,
        [SpecializedLaborRate] decimal(18,2) NOT NULL,
        [ElectricityRatePerKwh] decimal(18,2) NOT NULL,
        [GasRatePerUnit] decimal(18,2) NOT NULL,
        [WaterRatePerUnit] decimal(18,2) NOT NULL,
        [OvenOperatingCostPerHour] decimal(18,2) NOT NULL,
        [SandblasterCostPerHour] decimal(18,2) NOT NULL,
        [CoatingBoothCostPerHour] decimal(18,2) NOT NULL,
        [GeneralMarkupPercentage] decimal(18,2) NOT NULL,
        [AdminOverheadPercentage] decimal(18,2) NOT NULL,
        [FacilityCostPercentage] decimal(18,2) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_CompanyOperatingCosts] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_CompanyOperatingCosts_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206174417_AddCompanyOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T17:43:30.0415021Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206174417_AddCompanyOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T17:43:30.0415026Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206174417_AddCompanyOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T17:43:30.0415028Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206174417_AddCompanyOperatingCosts'
)
BEGIN
    CREATE UNIQUE INDEX [IX_CompanyOperatingCosts_CompanyId] ON [CompanyOperatingCosts] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206174417_AddCompanyOperatingCosts'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260206174417_AddCompanyOperatingCosts', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206213627_MakeCustomerEmailOptional'
)
BEGIN
    DROP INDEX [IX_Customers_Email] ON [Customers];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206213627_MakeCustomerEmailOptional'
)
BEGIN
    DECLARE @var1 sysname;
    SELECT @var1 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Customers]') AND [c].[name] = N'Email');
    IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Customers] DROP CONSTRAINT [' + @var1 + '];');
    ALTER TABLE [Customers] ALTER COLUMN [Email] nvarchar(450) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206213627_MakeCustomerEmailOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T21:35:23.2581715Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206213627_MakeCustomerEmailOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T21:35:23.2581722Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206213627_MakeCustomerEmailOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-06T21:35:23.2581724Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206213627_MakeCustomerEmailOptional'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_Customers_Email] ON [Customers] ([Email]) WHERE [Email] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260206213627_MakeCustomerEmailOptional'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260206213627_MakeCustomerEmailOptional', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    DECLARE @var2 sysname;
    SELECT @var2 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Quotes]') AND [c].[name] = N'CustomerId');
    IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Quotes] DROP CONSTRAINT [' + @var2 + '];');
    ALTER TABLE [Quotes] ALTER COLUMN [CustomerId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ProspectAddress] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ProspectCity] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ProspectCompanyName] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ProspectContactName] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ProspectEmail] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ProspectPhone] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ProspectState] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ProspectZipCode] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T03:42:43.2794915Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T03:42:43.2794919Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T03:42:43.2794921Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207034246_UpdateQuoteForProspects'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260207034246_UpdateQuoteForProspects', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207035534_AddPowderCoatingCostAndTaxToOperatingCosts'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [PowderCoatingCostPerSqFt] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207035534_AddPowderCoatingCostAndTaxToOperatingCosts'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [TaxPercent] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207035534_AddPowderCoatingCostAndTaxToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T03:55:32.3427640Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207035534_AddPowderCoatingCostAndTaxToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T03:55:32.3427647Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207035534_AddPowderCoatingCostAndTaxToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T03:55:32.3427649Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207035534_AddPowderCoatingCostAndTaxToOperatingCosts'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260207035534_AddPowderCoatingCostAndTaxToOperatingCosts', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [InventoryItemId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [PowderCostOverride] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [SurfaceAreaSqFt] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T04:32:10.0998342Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T04:32:10.0998349Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T04:32:10.0998351Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    CREATE INDEX [IX_QuoteItems_InventoryItemId] ON [QuoteItems] ([InventoryItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD CONSTRAINT [FK_QuoteItems_InventoryItems_InventoryItemId] FOREIGN KEY ([InventoryItemId]) REFERENCES [InventoryItems] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207043212_AddPowderCostFieldsToQuoteItems'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260207043212_AddPowderCostFieldsToQuoteItems', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207152856_AddCoverageSqFtPerLbToInventoryItem'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD [CoverageSqFtPerLb] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207152856_AddCoverageSqFtPerLbToInventoryItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T15:28:54.4593675Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207152856_AddCoverageSqFtPerLbToInventoryItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T15:28:54.4593680Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207152856_AddCoverageSqFtPerLbToInventoryItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T15:28:54.4593682Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207152856_AddCoverageSqFtPerLbToInventoryItem'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260207152856_AddCoverageSqFtPerLbToInventoryItem', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207153545_AddTransferEfficiencyToInventoryItem'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD [TransferEfficiency] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207153545_AddTransferEfficiencyToInventoryItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T15:35:42.9455847Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207153545_AddTransferEfficiencyToInventoryItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T15:35:42.9455851Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207153545_AddTransferEfficiencyToInventoryItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T15:35:42.9455853Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207153545_AddTransferEfficiencyToInventoryItem'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260207153545_AddTransferEfficiencyToInventoryItem', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD [AssignedWorkerId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    ALTER TABLE [Jobs] ADD [AssignedWorkerId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    CREATE TABLE [ShopWorkers] (
        [Id] int NOT NULL IDENTITY,
        [Name] nvarchar(max) NOT NULL,
        [Role] int NOT NULL,
        [Phone] nvarchar(max) NULL,
        [Email] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [Notes] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_ShopWorkers] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_ShopWorkers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T20:06:23.0605718Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T20:06:23.0605725Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-07T20:06:23.0605728Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    CREATE INDEX [IX_MaintenanceRecords_AssignedWorkerId] ON [MaintenanceRecords] ([AssignedWorkerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    CREATE INDEX [IX_Jobs_AssignedWorkerId] ON [Jobs] ([AssignedWorkerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    CREATE INDEX [IX_ShopWorkers_CompanyId] ON [ShopWorkers] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_ShopWorkers_AssignedWorkerId] FOREIGN KEY ([AssignedWorkerId]) REFERENCES [ShopWorkers] ([Id]) ON DELETE SET NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD CONSTRAINT [FK_MaintenanceRecords_ShopWorkers_AssignedWorkerId] FOREIGN KEY ([AssignedWorkerId]) REFERENCES [ShopWorkers] ([Id]) ON DELETE SET NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260207200633_AddShopWorkers'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260207200633_AddShopWorkers', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208160017_StoreLogoInDatabase'
)
BEGIN
    EXEC sp_rename N'[Companies].[LogoPath]', N'LogoContentType', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208160017_StoreLogoInDatabase'
)
BEGIN
    ALTER TABLE [Companies] ADD [LogoData] varbinary(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208160017_StoreLogoInDatabase'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T16:00:14.7529664Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208160017_StoreLogoInDatabase'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T16:00:14.7529711Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208160017_StoreLogoInDatabase'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T16:00:14.7529713Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208160017_StoreLogoInDatabase'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260208160017_StoreLogoInDatabase', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208164341_AddProfilePictureAndSidebarColor'
)
BEGIN
    EXEC sp_rename N'[AspNetUsers].[ProfilePicturePath]', N'SidebarColor', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208164341_AddProfilePictureAndSidebarColor'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [ProfilePictureContentType] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208164341_AddProfilePictureAndSidebarColor'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [ProfilePictureData] varbinary(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208164341_AddProfilePictureAndSidebarColor'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T16:43:39.0977992Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208164341_AddProfilePictureAndSidebarColor'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T16:43:39.0978000Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208164341_AddProfilePictureAndSidebarColor'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T16:43:39.0978002Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208164341_AddProfilePictureAndSidebarColor'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260208164341_AddProfilePictureAndSidebarColor', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208181438_AddCompanyPreferences'
)
BEGIN
    CREATE TABLE [CompanyPreferences] (
        [Id] int NOT NULL IDENTITY,
        [CompanyId] int NOT NULL,
        [DefaultCurrency] nvarchar(max) NOT NULL,
        [DefaultDateFormat] nvarchar(max) NOT NULL,
        [DefaultTimeFormat] nvarchar(max) NOT NULL,
        [DefaultPaymentTerms] nvarchar(max) NOT NULL,
        [DefaultQuoteValidityDays] int NOT NULL,
        [QuoteNumberPrefix] nvarchar(max) NOT NULL,
        [JobNumberPrefix] nvarchar(max) NOT NULL,
        [DefaultJobPriority] nvarchar(max) NOT NULL,
        [RequireCustomerPO] bit NOT NULL,
        [AllowCustomerApproval] bit NOT NULL,
        [DefaultTurnaroundDays] int NOT NULL,
        [EnableSandblastingStep] bit NOT NULL,
        [EnableMaskingStep] bit NOT NULL,
        [EmailNotificationsEnabled] bit NOT NULL,
        [NotifyOnNewJob] bit NOT NULL,
        [NotifyOnJobStatusChange] bit NOT NULL,
        [NotifyOnQuoteApproval] bit NOT NULL,
        [NotifyOnPaymentReceived] bit NOT NULL,
        [QuoteExpiryWarningDays] int NOT NULL,
        [DueDateWarningDays] int NOT NULL,
        [MaintenanceAlertDays] int NOT NULL,
        [QuoteRetentionYears] int NOT NULL,
        [JobRetentionYears] int NOT NULL,
        [LogRetentionDays] int NOT NULL,
        [AutoArchiveJobsDays] int NOT NULL,
        [DeletedRecordRetentionDays] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_CompanyPreferences] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_CompanyPreferences_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208181438_AddCompanyPreferences'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T18:14:35.8493756Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208181438_AddCompanyPreferences'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T18:14:35.8493760Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208181438_AddCompanyPreferences'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T18:14:35.8493762Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208181438_AddCompanyPreferences'
)
BEGIN
    CREATE UNIQUE INDEX [IX_CompanyPreferences_CompanyId] ON [CompanyPreferences] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208181438_AddCompanyPreferences'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260208181438_AddCompanyPreferences', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208224426_AddTaxExemptionToCustomer'
)
BEGIN
    ALTER TABLE [Customers] ADD [IsTaxExempt] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208224426_AddTaxExemptionToCustomer'
)
BEGIN
    ALTER TABLE [Customers] ADD [TaxExemptCertificateContentType] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208224426_AddTaxExemptionToCustomer'
)
BEGIN
    ALTER TABLE [Customers] ADD [TaxExemptCertificateData] varbinary(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208224426_AddTaxExemptionToCustomer'
)
BEGIN
    ALTER TABLE [Customers] ADD [TaxExemptCertificateFileName] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208224426_AddTaxExemptionToCustomer'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T22:44:23.0992986Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208224426_AddTaxExemptionToCustomer'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T22:44:23.0992993Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208224426_AddTaxExemptionToCustomer'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T22:44:23.0992995Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208224426_AddTaxExemptionToCustomer'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260208224426_AddTaxExemptionToCustomer', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208230323_AddRushChargePercentage'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [RushChargePercentage] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208230323_AddRushChargePercentage'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T23:03:20.9733994Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208230323_AddRushChargePercentage'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T23:03:20.9733999Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208230323_AddRushChargePercentage'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T23:03:20.9734001Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208230323_AddRushChargePercentage'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260208230323_AddRushChargePercentage', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208231408_AddShopMinimumCharge'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [ShopMinimumCharge] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208231408_AddShopMinimumCharge'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T23:14:05.6375506Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208231408_AddShopMinimumCharge'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T23:14:05.6375510Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208231408_AddShopMinimumCharge'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-08T23:14:05.6375512Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260208231408_AddShopMinimumCharge'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260208231408_AddShopMinimumCharge', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211002823_AddProfilePictureFilePath'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [ProfilePictureFilePath] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211002823_AddProfilePictureFilePath'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T00:28:19.8975461Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211002823_AddProfilePictureFilePath'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T00:28:19.8975466Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211002823_AddProfilePictureFilePath'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T00:28:19.8975469Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211002823_AddProfilePictureFilePath'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260211002823_AddProfilePictureFilePath', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    EXEC sp_rename N'[JobPhotos].[PhotoDate]', N'UploadedDate', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    EXEC sp_rename N'[JobPhotos].[Description]', N'Caption', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    DECLARE @var3 sysname;
    SELECT @var3 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobPhotos]') AND [c].[name] = N'PhotoType');
    IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [JobPhotos] DROP CONSTRAINT [' + @var3 + '];');
    ALTER TABLE [JobPhotos] ALTER COLUMN [PhotoType] int NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    ALTER TABLE [JobPhotos] ADD [ContentType] nvarchar(max) NOT NULL DEFAULT N'';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    ALTER TABLE [JobPhotos] ADD [DisplayOrder] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    ALTER TABLE [JobPhotos] ADD [FileSize] bigint NOT NULL DEFAULT CAST(0 AS bigint);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    ALTER TABLE [JobPhotos] ADD [UploadedById] nvarchar(450) NOT NULL DEFAULT N'';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T00:54:54.2629259Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T00:54:54.2629263Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T00:54:54.2629265Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    CREATE INDEX [IX_JobPhotos_UploadedById] ON [JobPhotos] ([UploadedById]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    ALTER TABLE [JobPhotos] ADD CONSTRAINT [FK_JobPhotos_AspNetUsers_UploadedById] FOREIGN KEY ([UploadedById]) REFERENCES [AspNetUsers] ([Id]) ON DELETE CASCADE;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211005456_UpdateJobPhotoEntity'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260211005456_UpdateJobPhotoEntity', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    ALTER TABLE [Equipment] ADD [ManualContentType] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    ALTER TABLE [Equipment] ADD [ManualFileName] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    ALTER TABLE [Equipment] ADD [ManualFilePath] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    ALTER TABLE [Equipment] ADD [ManualFileSize] bigint NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    ALTER TABLE [Equipment] ADD [ManualUploadedDate] datetime2 NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    ALTER TABLE [Companies] ADD [LogoFilePath] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T02:06:13.9839041Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T02:06:13.9839046Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T02:06:13.9839048Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211020617_AddFileSystemStorageForLogosAndManuals'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260211020617_AddFileSystemStorageForLogosAndManuals', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    CREATE TABLE [CatalogCategories] (
        [Id] int NOT NULL IDENTITY,
        [Name] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NULL,
        [ParentCategoryId] int NULL,
        [DisplayOrder] int NOT NULL,
        [IsActive] bit NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_CatalogCategories] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_CatalogCategories_CatalogCategories_ParentCategoryId] FOREIGN KEY ([ParentCategoryId]) REFERENCES [CatalogCategories] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_CatalogCategories_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    CREATE TABLE [CatalogItems] (
        [Id] int NOT NULL IDENTITY,
        [Name] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NULL,
        [SKU] nvarchar(max) NULL,
        [CategoryId] int NOT NULL,
        [DefaultPrice] decimal(18,2) NOT NULL,
        [DefaultRequiresSandblasting] bit NOT NULL,
        [DefaultRequiresMasking] bit NOT NULL,
        [DefaultEstimatedMinutes] int NULL,
        [DisplayOrder] int NOT NULL,
        [IsActive] bit NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_CatalogItems] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_CatalogItems_CatalogCategories_CategoryId] FOREIGN KEY ([CategoryId]) REFERENCES [CatalogCategories] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_CatalogItems_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T02:47:52.8155540Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T02:47:52.8155546Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T02:47:52.8155548Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    CREATE INDEX [IX_CatalogCategories_CompanyId] ON [CatalogCategories] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    CREATE INDEX [IX_CatalogCategories_ParentCategoryId] ON [CatalogCategories] ([ParentCategoryId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    CREATE INDEX [IX_CatalogItems_CategoryId] ON [CatalogItems] ([CategoryId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    CREATE INDEX [IX_CatalogItems_CompanyId] ON [CatalogItems] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211024755_AddProductCatalog'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260211024755_AddProductCatalog', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211043819_AddCatalogItemIdToQuoteItems'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [CatalogItemId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211043819_AddCatalogItemIdToQuoteItems'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T04:38:17.1662142Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211043819_AddCatalogItemIdToQuoteItems'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T04:38:17.1662149Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211043819_AddCatalogItemIdToQuoteItems'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T04:38:17.1662151Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211043819_AddCatalogItemIdToQuoteItems'
)
BEGIN
    CREATE INDEX [IX_QuoteItems_CatalogItemId] ON [QuoteItems] ([CatalogItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211043819_AddCatalogItemIdToQuoteItems'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD CONSTRAINT [FK_QuoteItems_CatalogItems_CatalogItemId] FOREIGN KEY ([CatalogItemId]) REFERENCES [CatalogItems] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211043819_AddCatalogItemIdToQuoteItems'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260211043819_AddCatalogItemIdToQuoteItems', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    DECLARE @var4 sysname;
    SELECT @var4 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyOperatingCosts]') AND [c].[name] = N'AdminOverheadPercentage');
    IF @var4 IS NOT NULL EXEC(N'ALTER TABLE [CompanyOperatingCosts] DROP CONSTRAINT [' + @var4 + '];');
    ALTER TABLE [CompanyOperatingCosts] DROP COLUMN [AdminOverheadPercentage];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    DECLARE @var5 sysname;
    SELECT @var5 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyOperatingCosts]') AND [c].[name] = N'ElectricityRatePerKwh');
    IF @var5 IS NOT NULL EXEC(N'ALTER TABLE [CompanyOperatingCosts] DROP CONSTRAINT [' + @var5 + '];');
    ALTER TABLE [CompanyOperatingCosts] DROP COLUMN [ElectricityRatePerKwh];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    DECLARE @var6 sysname;
    SELECT @var6 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyOperatingCosts]') AND [c].[name] = N'FacilityCostPercentage');
    IF @var6 IS NOT NULL EXEC(N'ALTER TABLE [CompanyOperatingCosts] DROP CONSTRAINT [' + @var6 + '];');
    ALTER TABLE [CompanyOperatingCosts] DROP COLUMN [FacilityCostPercentage];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    DECLARE @var7 sysname;
    SELECT @var7 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyOperatingCosts]') AND [c].[name] = N'GasRatePerUnit');
    IF @var7 IS NOT NULL EXEC(N'ALTER TABLE [CompanyOperatingCosts] DROP CONSTRAINT [' + @var7 + '];');
    ALTER TABLE [CompanyOperatingCosts] DROP COLUMN [GasRatePerUnit];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    DECLARE @var8 sysname;
    SELECT @var8 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyOperatingCosts]') AND [c].[name] = N'OvertimeLaborRate');
    IF @var8 IS NOT NULL EXEC(N'ALTER TABLE [CompanyOperatingCosts] DROP CONSTRAINT [' + @var8 + '];');
    ALTER TABLE [CompanyOperatingCosts] DROP COLUMN [OvertimeLaborRate];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    DECLARE @var9 sysname;
    SELECT @var9 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyOperatingCosts]') AND [c].[name] = N'SpecializedLaborRate');
    IF @var9 IS NOT NULL EXEC(N'ALTER TABLE [CompanyOperatingCosts] DROP CONSTRAINT [' + @var9 + '];');
    ALTER TABLE [CompanyOperatingCosts] DROP COLUMN [SpecializedLaborRate];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    EXEC sp_rename N'[CompanyOperatingCosts].[WaterRatePerUnit]', N'RushChargeFixedAmount', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [RushChargeType] nvarchar(20) NOT NULL DEFAULT N'Percentage';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T19:55:20.0897507Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T19:55:20.0897511Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-11T19:55:20.0897513Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260211195523_UpdateOperatingCostsRushCharge'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260211195523_UpdateOperatingCostsRushCharge', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    ALTER TABLE [Jobs] DROP CONSTRAINT [FK_Jobs_AspNetUsers_AssignedEmployeeId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DROP INDEX [IX_Jobs_AssignedEmployeeId] ON [Jobs];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var10 sysname;
    SELECT @var10 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Quotes]') AND [c].[name] = N'AIPriceRationale');
    IF @var10 IS NOT NULL EXEC(N'ALTER TABLE [Quotes] DROP CONSTRAINT [' + @var10 + '];');
    ALTER TABLE [Quotes] DROP COLUMN [AIPriceRationale];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var11 sysname;
    SELECT @var11 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Quotes]') AND [c].[name] = N'AISuggestedPrice');
    IF @var11 IS NOT NULL EXEC(N'ALTER TABLE [Quotes] DROP CONSTRAINT [' + @var11 + '];');
    ALTER TABLE [Quotes] DROP COLUMN [AISuggestedPrice];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var12 sysname;
    SELECT @var12 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Quotes]') AND [c].[name] = N'UsedAISuggestion');
    IF @var12 IS NOT NULL EXEC(N'ALTER TABLE [Quotes] DROP CONSTRAINT [' + @var12 + '];');
    ALTER TABLE [Quotes] DROP COLUMN [UsedAISuggestion];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var13 sysname;
    SELECT @var13 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'Height');
    IF @var13 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var13 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [Height];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var14 sysname;
    SELECT @var14 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'Length');
    IF @var14 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var14 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [Length];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var15 sysname;
    SELECT @var15 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'MeasurementUnit');
    IF @var15 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var15 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [MeasurementUnit];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var16 sysname;
    SELECT @var16 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'Width');
    IF @var16 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var16 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [Width];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var17 sysname;
    SELECT @var17 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'ActualCost');
    IF @var17 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var17 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [ActualCost];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var18 sysname;
    SELECT @var18 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'ActualHours');
    IF @var18 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var18 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [ActualHours];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var19 sysname;
    SELECT @var19 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'AssignedEmployeeId');
    IF @var19 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var19 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [AssignedEmployeeId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var20 sysname;
    SELECT @var20 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'CustomerApprovedDate');
    IF @var20 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var20 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [CustomerApprovedDate];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var21 sysname;
    SELECT @var21 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'EstimatedCost');
    IF @var21 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var21 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [EstimatedCost];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var22 sysname;
    SELECT @var22 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'EstimatedHours');
    IF @var22 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var22 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [EstimatedHours];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var23 sysname;
    SELECT @var23 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobItems]') AND [c].[name] = N'ActualMinutes');
    IF @var23 IS NOT NULL EXEC(N'ALTER TABLE [JobItems] DROP CONSTRAINT [' + @var23 + '];');
    ALTER TABLE [JobItems] DROP COLUMN [ActualMinutes];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var24 sysname;
    SELECT @var24 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobItems]') AND [c].[name] = N'Height');
    IF @var24 IS NOT NULL EXEC(N'ALTER TABLE [JobItems] DROP CONSTRAINT [' + @var24 + '];');
    ALTER TABLE [JobItems] DROP COLUMN [Height];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var25 sysname;
    SELECT @var25 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobItems]') AND [c].[name] = N'Length');
    IF @var25 IS NOT NULL EXEC(N'ALTER TABLE [JobItems] DROP CONSTRAINT [' + @var25 + '];');
    ALTER TABLE [JobItems] DROP COLUMN [Length];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var26 sysname;
    SELECT @var26 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobItems]') AND [c].[name] = N'MaterialCost');
    IF @var26 IS NOT NULL EXEC(N'ALTER TABLE [JobItems] DROP CONSTRAINT [' + @var26 + '];');
    ALTER TABLE [JobItems] DROP COLUMN [MaterialCost];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var27 sysname;
    SELECT @var27 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobItems]') AND [c].[name] = N'MeasurementUnit');
    IF @var27 IS NOT NULL EXEC(N'ALTER TABLE [JobItems] DROP CONSTRAINT [' + @var27 + '];');
    ALTER TABLE [JobItems] DROP COLUMN [MeasurementUnit];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var28 sysname;
    SELECT @var28 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobItems]') AND [c].[name] = N'Weight');
    IF @var28 IS NOT NULL EXEC(N'ALTER TABLE [JobItems] DROP CONSTRAINT [' + @var28 + '];');
    ALTER TABLE [JobItems] DROP COLUMN [Weight];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    DECLARE @var29 sysname;
    SELECT @var29 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobItems]') AND [c].[name] = N'Width');
    IF @var29 IS NOT NULL EXEC(N'ALTER TABLE [JobItems] DROP CONSTRAINT [' + @var29 + '];');
    ALTER TABLE [JobItems] DROP COLUMN [Width];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T13:50:54.4827815Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T13:50:54.4827821Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T13:50:54.4827822Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213135057_RemoveUnusedFields'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260213135057_RemoveUnusedFields', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [AccountNumber] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [CreditLimit] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [IsPreferred] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [PaymentTerms] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [TaxId] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T16:25:10.0855660Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T16:25:10.0855668Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T16:25:10.0855669Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213162512_AddSupplierEnhancements'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260213162512_AddSupplierEnhancements', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Jobs] ADD [OldStatus] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Jobs] ADD [OldPriority] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Quotes] ADD [OldStatus] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [JobStatusHistory] ADD [OldFromStatus] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [JobStatusHistory] ADD [OldToStatus] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    UPDATE Jobs SET OldStatus = Status, OldPriority = Priority
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    UPDATE Quotes SET OldStatus = Status
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    UPDATE JobStatusHistory SET OldFromStatus = FromStatus, OldToStatus = ToStatus
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE TABLE [JobStatusLookups] (
        [Id] int NOT NULL IDENTITY,
        [StatusCode] nvarchar(450) NOT NULL,
        [DisplayName] nvarchar(max) NOT NULL,
        [DisplayOrder] int NOT NULL,
        [ColorClass] nvarchar(max) NOT NULL,
        [IconClass] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [IsSystemDefined] bit NOT NULL,
        [IsTerminalStatus] bit NOT NULL,
        [IsWorkInProgressStatus] bit NOT NULL,
        [Description] nvarchar(max) NULL,
        [WorkflowCategory] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobStatusLookups] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobStatusLookups_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE TABLE [JobPriorityLookups] (
        [Id] int NOT NULL IDENTITY,
        [PriorityCode] nvarchar(450) NOT NULL,
        [DisplayName] nvarchar(max) NOT NULL,
        [DisplayOrder] int NOT NULL,
        [ColorClass] nvarchar(max) NOT NULL,
        [IconClass] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [IsSystemDefined] bit NOT NULL,
        [Description] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobPriorityLookups] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobPriorityLookups_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE TABLE [QuoteStatusLookups] (
        [Id] int NOT NULL IDENTITY,
        [StatusCode] nvarchar(450) NOT NULL,
        [DisplayName] nvarchar(max) NOT NULL,
        [DisplayOrder] int NOT NULL,
        [ColorClass] nvarchar(max) NOT NULL,
        [IconClass] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [IsSystemDefined] bit NOT NULL,
        [IsApprovedStatus] bit NOT NULL,
        [IsConvertedStatus] bit NOT NULL,
        [IsDraftStatus] bit NOT NULL,
        [Description] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_QuoteStatusLookups] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_QuoteStatusLookups_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN

                    INSERT INTO JobStatusLookups (StatusCode, DisplayName, DisplayOrder, ColorClass, IconClass, IsActive, IsSystemDefined, IsTerminalStatus, IsWorkInProgressStatus, Description, WorkflowCategory, CompanyId, CreatedAt, IsDeleted)
                    SELECT
                        s.StatusCode, s.DisplayName, s.DisplayOrder, s.ColorClass, s.IconClass, s.IsActive, s.IsSystemDefined, s.IsTerminalStatus, s.IsWorkInProgressStatus, s.Description, s.WorkflowCategory, c.Id, GETUTCDATE(), 0
                    FROM Companies c
                    CROSS JOIN (VALUES
                        ('PENDING', 'Pending', 1, 'secondary', 'bi-clock', 1, 1, 0, 0, 'Job is pending approval or scheduling', 'Pre-Production'),
                        ('QUOTED', 'Quoted', 2, 'info', 'bi-file-earmark-text', 1, 0, 0, 0, 'Quote has been generated', 'Pre-Production'),
                        ('APPROVED', 'Approved', 3, 'primary', 'bi-check-circle', 1, 0, 0, 0, 'Job has been approved', 'Pre-Production'),
                        ('IN_PREPARATION', 'In Preparation', 4, 'warning', 'bi-tools', 1, 0, 0, 1, 'Job is being prepared', 'Production'),
                        ('SANDBLASTING', 'Sandblasting', 5, 'warning', 'bi-hurricane', 1, 0, 0, 1, 'Surface preparation in progress', 'Production'),
                        ('MASKING_TAPING', 'Masking/Taping', 6, 'warning', 'bi-scissors', 1, 0, 0, 1, 'Masking areas for coating', 'Production'),
                        ('CLEANING', 'Cleaning', 7, 'warning', 'bi-droplet', 1, 0, 0, 1, 'Pre-coat cleaning', 'Production'),
                        ('IN_OVEN', 'In Oven', 8, 'warning', 'bi-thermometer-half', 1, 0, 0, 1, 'Pre-heating in oven', 'Production'),
                        ('COATING', 'Coating', 9, 'warning', 'bi-paint-bucket', 1, 0, 0, 1, 'Applying powder coating', 'Production'),
                        ('CURING', 'Curing', 10, 'warning', 'bi-thermometer-sun', 1, 0, 0, 1, 'Heat curing the coating', 'Production'),
                        ('QUALITY_CHECK', 'Quality Check', 11, 'info', 'bi-search', 1, 0, 0, 1, 'Quality inspection', 'Production'),
                        ('COMPLETED', 'Completed', 12, 'success', 'bi-check-all', 1, 1, 1, 0, 'Job is completed', 'Post-Production'),
                        ('READY_FOR_PICKUP', 'Ready for Pickup', 13, 'success', 'bi-box-seam', 1, 0, 0, 0, 'Ready for customer pickup', 'Post-Production'),
                        ('DELIVERED', 'Delivered', 14, 'success', 'bi-truck', 1, 0, 1, 0, 'Delivered to customer', 'Post-Production'),
                        ('ON_HOLD', 'On Hold', 15, 'dark', 'bi-pause-circle', 1, 0, 0, 0, 'Job is temporarily on hold', 'Other'),
                        ('CANCELLED', 'Cancelled', 16, 'danger', 'bi-x-circle', 1, 1, 1, 0, 'Job has been cancelled', 'Other')
                    ) AS s(StatusCode, DisplayName, DisplayOrder, ColorClass, IconClass, IsActive, IsSystemDefined, IsTerminalStatus, IsWorkInProgressStatus, Description, WorkflowCategory)
                    WHERE c.IsDeleted = 0
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN

                    INSERT INTO JobPriorityLookups (PriorityCode, DisplayName, DisplayOrder, ColorClass, IconClass, IsActive, IsSystemDefined, Description, CompanyId, CreatedAt, IsDeleted)
                    SELECT
                        p.PriorityCode, p.DisplayName, p.DisplayOrder, p.ColorClass, p.IconClass, p.IsActive, p.IsSystemDefined, p.Description, c.Id, GETUTCDATE(), 0
                    FROM Companies c
                    CROSS JOIN (VALUES
                        ('LOW', 'Low', 1, 'secondary', 'bi-arrow-down', 1, 0, 'Low priority job'),
                        ('NORMAL', 'Normal', 2, 'primary', NULL, 1, 1, 'Standard priority job'),
                        ('HIGH', 'High', 3, 'info', 'bi-arrow-up', 1, 0, 'High priority job'),
                        ('URGENT', 'Urgent', 4, 'warning', 'bi-exclamation-triangle', 1, 0, 'Urgent job - expedited processing'),
                        ('RUSH', 'Rush', 5, 'danger', 'bi-lightning', 1, 0, 'Rush job - immediate processing required')
                    ) AS p(PriorityCode, DisplayName, DisplayOrder, ColorClass, IconClass, IsActive, IsSystemDefined, Description)
                    WHERE c.IsDeleted = 0
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN

                    INSERT INTO QuoteStatusLookups (StatusCode, DisplayName, DisplayOrder, ColorClass, IconClass, IsActive, IsSystemDefined, IsApprovedStatus, IsConvertedStatus, IsDraftStatus, Description, CompanyId, CreatedAt, IsDeleted)
                    SELECT
                        qs.StatusCode, qs.DisplayName, qs.DisplayOrder, qs.ColorClass, qs.IconClass, qs.IsActive, qs.IsSystemDefined, qs.IsApprovedStatus, qs.IsConvertedStatus, qs.IsDraftStatus, qs.Description, c.Id, GETUTCDATE(), 0
                    FROM Companies c
                    CROSS JOIN (VALUES
                        ('DRAFT', 'Draft', 1, 'secondary', 'bi-pencil', 1, 1, 0, 0, 1, 'Quote is being drafted'),
                        ('SENT', 'Sent', 2, 'info', 'bi-send', 1, 0, 0, 0, 0, 'Quote has been sent to customer'),
                        ('APPROVED', 'Approved', 3, 'success', 'bi-check-circle', 1, 1, 1, 0, 0, 'Quote has been approved by customer'),
                        ('REJECTED', 'Rejected', 4, 'danger', 'bi-x-circle', 1, 0, 0, 0, 0, 'Quote was rejected by customer'),
                        ('EXPIRED', 'Expired', 5, 'dark', 'bi-clock-history', 1, 0, 0, 0, 0, 'Quote has expired'),
                        ('CONVERTED', 'Converted', 6, 'primary', 'bi-arrow-right-circle', 1, 1, 0, 1, 0, 'Quote has been converted to job'),
                        ('REVISED', 'Revised', 7, 'warning', 'bi-arrow-clockwise', 1, 0, 0, 0, 0, 'Quote is being revised')
                    ) AS qs(StatusCode, DisplayName, DisplayOrder, ColorClass, IconClass, IsActive, IsSystemDefined, IsApprovedStatus, IsConvertedStatus, IsDraftStatus, Description)
                    WHERE c.IsDeleted = 0
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    EXEC sp_rename N'[Jobs].[Status]', N'JobStatusId_OLD', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    EXEC sp_rename N'[Jobs].[Priority]', N'JobPriorityId_OLD', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    EXEC sp_rename N'[Quotes].[Status]', N'QuoteStatusId_OLD', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    EXEC sp_rename N'[JobStatusHistory].[FromStatus]', N'FromStatusId_OLD', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    EXEC sp_rename N'[JobStatusHistory].[ToStatus]', N'ToStatusId_OLD', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Jobs] ADD [JobStatusId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Jobs] ADD [JobPriorityId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Quotes] ADD [QuoteStatusId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [JobStatusHistory] ADD [FromStatusId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [JobStatusHistory] ADD [ToStatusId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN

                    UPDATE j
                    SET j.JobStatusId = s.Id
                    FROM Jobs j
                    INNER JOIN JobStatusLookups s ON j.CompanyId = s.CompanyId
                    WHERE s.StatusCode = CASE j.OldStatus
                        WHEN 0 THEN 'PENDING'
                        WHEN 1 THEN 'QUOTED'
                        WHEN 2 THEN 'APPROVED'
                        WHEN 3 THEN 'IN_PREPARATION'
                        WHEN 4 THEN 'SANDBLASTING'
                        WHEN 5 THEN 'MASKING_TAPING'
                        WHEN 6 THEN 'CLEANING'
                        WHEN 7 THEN 'IN_OVEN'
                        WHEN 8 THEN 'COATING'
                        WHEN 9 THEN 'CURING'
                        WHEN 10 THEN 'QUALITY_CHECK'
                        WHEN 11 THEN 'COMPLETED'
                        WHEN 12 THEN 'READY_FOR_PICKUP'
                        WHEN 13 THEN 'DELIVERED'
                        WHEN 14 THEN 'ON_HOLD'
                        WHEN 15 THEN 'CANCELLED'
                    END
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN

                    UPDATE j
                    SET j.JobPriorityId = p.Id
                    FROM Jobs j
                    INNER JOIN JobPriorityLookups p ON j.CompanyId = p.CompanyId
                    WHERE p.PriorityCode = CASE j.OldPriority
                        WHEN 0 THEN 'LOW'
                        WHEN 1 THEN 'NORMAL'
                        WHEN 2 THEN 'HIGH'
                        WHEN 3 THEN 'URGENT'
                        WHEN 4 THEN 'RUSH'
                    END
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN

                    UPDATE q
                    SET q.QuoteStatusId = s.Id
                    FROM Quotes q
                    INNER JOIN QuoteStatusLookups s ON q.CompanyId = s.CompanyId
                    WHERE s.StatusCode = CASE q.OldStatus
                        WHEN 0 THEN 'DRAFT'
                        WHEN 1 THEN 'SENT'
                        WHEN 2 THEN 'APPROVED'
                        WHEN 3 THEN 'REJECTED'
                        WHEN 4 THEN 'EXPIRED'
                        WHEN 5 THEN 'CONVERTED'
                        WHEN 6 THEN 'REVISED'
                    END
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN

                    UPDATE h
                    SET h.FromStatusId = s.Id
                    FROM JobStatusHistory h
                    INNER JOIN Jobs j ON h.JobId = j.Id
                    INNER JOIN JobStatusLookups s ON j.CompanyId = s.CompanyId
                    WHERE s.StatusCode = CASE h.OldFromStatus
                        WHEN 0 THEN 'PENDING'
                        WHEN 1 THEN 'QUOTED'
                        WHEN 2 THEN 'APPROVED'
                        WHEN 3 THEN 'IN_PREPARATION'
                        WHEN 4 THEN 'SANDBLASTING'
                        WHEN 5 THEN 'MASKING_TAPING'
                        WHEN 6 THEN 'CLEANING'
                        WHEN 7 THEN 'IN_OVEN'
                        WHEN 8 THEN 'COATING'
                        WHEN 9 THEN 'CURING'
                        WHEN 10 THEN 'QUALITY_CHECK'
                        WHEN 11 THEN 'COMPLETED'
                        WHEN 12 THEN 'READY_FOR_PICKUP'
                        WHEN 13 THEN 'DELIVERED'
                        WHEN 14 THEN 'ON_HOLD'
                        WHEN 15 THEN 'CANCELLED'
                    END
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN

                    UPDATE h
                    SET h.ToStatusId = s.Id
                    FROM JobStatusHistory h
                    INNER JOIN Jobs j ON h.JobId = j.Id
                    INNER JOIN JobStatusLookups s ON j.CompanyId = s.CompanyId
                    WHERE s.StatusCode = CASE h.OldToStatus
                        WHEN 0 THEN 'PENDING'
                        WHEN 1 THEN 'QUOTED'
                        WHEN 2 THEN 'APPROVED'
                        WHEN 3 THEN 'IN_PREPARATION'
                        WHEN 4 THEN 'SANDBLASTING'
                        WHEN 5 THEN 'MASKING_TAPING'
                        WHEN 6 THEN 'CLEANING'
                        WHEN 7 THEN 'IN_OVEN'
                        WHEN 8 THEN 'COATING'
                        WHEN 9 THEN 'CURING'
                        WHEN 10 THEN 'QUALITY_CHECK'
                        WHEN 11 THEN 'COMPLETED'
                        WHEN 12 THEN 'READY_FOR_PICKUP'
                        WHEN 13 THEN 'DELIVERED'
                        WHEN 14 THEN 'ON_HOLD'
                        WHEN 15 THEN 'CANCELLED'
                    END
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var30 sysname;
    SELECT @var30 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'JobStatusId');
    IF @var30 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var30 + '];');
    ALTER TABLE [Jobs] ALTER COLUMN [JobStatusId] int NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var31 sysname;
    SELECT @var31 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'JobPriorityId');
    IF @var31 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var31 + '];');
    ALTER TABLE [Jobs] ALTER COLUMN [JobPriorityId] int NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var32 sysname;
    SELECT @var32 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Quotes]') AND [c].[name] = N'QuoteStatusId');
    IF @var32 IS NOT NULL EXEC(N'ALTER TABLE [Quotes] DROP CONSTRAINT [' + @var32 + '];');
    ALTER TABLE [Quotes] ALTER COLUMN [QuoteStatusId] int NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var33 sysname;
    SELECT @var33 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobStatusHistory]') AND [c].[name] = N'FromStatusId');
    IF @var33 IS NOT NULL EXEC(N'ALTER TABLE [JobStatusHistory] DROP CONSTRAINT [' + @var33 + '];');
    ALTER TABLE [JobStatusHistory] ALTER COLUMN [FromStatusId] int NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var34 sysname;
    SELECT @var34 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobStatusHistory]') AND [c].[name] = N'ToStatusId');
    IF @var34 IS NOT NULL EXEC(N'ALTER TABLE [JobStatusHistory] DROP CONSTRAINT [' + @var34 + '];');
    ALTER TABLE [JobStatusHistory] ALTER COLUMN [ToStatusId] int NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE INDEX [IX_Jobs_JobStatusId] ON [Jobs] ([JobStatusId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE INDEX [IX_Jobs_JobPriorityId] ON [Jobs] ([JobPriorityId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE INDEX [IX_Quotes_QuoteStatusId] ON [Quotes] ([QuoteStatusId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE INDEX [IX_JobStatusHistory_FromStatusId] ON [JobStatusHistory] ([FromStatusId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE INDEX [IX_JobStatusHistory_ToStatusId] ON [JobStatusHistory] ([ToStatusId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE INDEX [IX_JobStatusLookups_CompanyId] ON [JobStatusLookups] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE UNIQUE INDEX [IX_JobStatusLookups_CompanyId_StatusCode] ON [JobStatusLookups] ([CompanyId], [StatusCode]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE INDEX [IX_JobPriorityLookups_CompanyId] ON [JobPriorityLookups] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE UNIQUE INDEX [IX_JobPriorityLookups_CompanyId_PriorityCode] ON [JobPriorityLookups] ([CompanyId], [PriorityCode]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE INDEX [IX_QuoteStatusLookups_CompanyId] ON [QuoteStatusLookups] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    CREATE UNIQUE INDEX [IX_QuoteStatusLookups_CompanyId_StatusCode] ON [QuoteStatusLookups] ([CompanyId], [StatusCode]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_JobStatusLookups_JobStatusId] FOREIGN KEY ([JobStatusId]) REFERENCES [JobStatusLookups] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_JobPriorityLookups_JobPriorityId] FOREIGN KEY ([JobPriorityId]) REFERENCES [JobPriorityLookups] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [Quotes] ADD CONSTRAINT [FK_Quotes_QuoteStatusLookups_QuoteStatusId] FOREIGN KEY ([QuoteStatusId]) REFERENCES [QuoteStatusLookups] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [JobStatusHistory] ADD CONSTRAINT [FK_JobStatusHistory_JobStatusLookups_FromStatusId] FOREIGN KEY ([FromStatusId]) REFERENCES [JobStatusLookups] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    ALTER TABLE [JobStatusHistory] ADD CONSTRAINT [FK_JobStatusHistory_JobStatusLookups_ToStatusId] FOREIGN KEY ([ToStatusId]) REFERENCES [JobStatusLookups] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var35 sysname;
    SELECT @var35 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'OldStatus');
    IF @var35 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var35 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [OldStatus];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var36 sysname;
    SELECT @var36 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'OldPriority');
    IF @var36 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var36 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [OldPriority];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var37 sysname;
    SELECT @var37 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Quotes]') AND [c].[name] = N'OldStatus');
    IF @var37 IS NOT NULL EXEC(N'ALTER TABLE [Quotes] DROP CONSTRAINT [' + @var37 + '];');
    ALTER TABLE [Quotes] DROP COLUMN [OldStatus];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var38 sysname;
    SELECT @var38 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobStatusHistory]') AND [c].[name] = N'OldFromStatus');
    IF @var38 IS NOT NULL EXEC(N'ALTER TABLE [JobStatusHistory] DROP CONSTRAINT [' + @var38 + '];');
    ALTER TABLE [JobStatusHistory] DROP COLUMN [OldFromStatus];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var39 sysname;
    SELECT @var39 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobStatusHistory]') AND [c].[name] = N'OldToStatus');
    IF @var39 IS NOT NULL EXEC(N'ALTER TABLE [JobStatusHistory] DROP CONSTRAINT [' + @var39 + '];');
    ALTER TABLE [JobStatusHistory] DROP COLUMN [OldToStatus];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var40 sysname;
    SELECT @var40 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'JobStatusId_OLD');
    IF @var40 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var40 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [JobStatusId_OLD];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var41 sysname;
    SELECT @var41 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Jobs]') AND [c].[name] = N'JobPriorityId_OLD');
    IF @var41 IS NOT NULL EXEC(N'ALTER TABLE [Jobs] DROP CONSTRAINT [' + @var41 + '];');
    ALTER TABLE [Jobs] DROP COLUMN [JobPriorityId_OLD];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var42 sysname;
    SELECT @var42 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Quotes]') AND [c].[name] = N'QuoteStatusId_OLD');
    IF @var42 IS NOT NULL EXEC(N'ALTER TABLE [Quotes] DROP CONSTRAINT [' + @var42 + '];');
    ALTER TABLE [Quotes] DROP COLUMN [QuoteStatusId_OLD];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var43 sysname;
    SELECT @var43 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobStatusHistory]') AND [c].[name] = N'FromStatusId_OLD');
    IF @var43 IS NOT NULL EXEC(N'ALTER TABLE [JobStatusHistory] DROP CONSTRAINT [' + @var43 + '];');
    ALTER TABLE [JobStatusHistory] DROP COLUMN [FromStatusId_OLD];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    DECLARE @var44 sysname;
    SELECT @var44 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobStatusHistory]') AND [c].[name] = N'ToStatusId_OLD');
    IF @var44 IS NOT NULL EXEC(N'ALTER TABLE [JobStatusHistory] DROP CONSTRAINT [' + @var44 + '];');
    ALTER TABLE [JobStatusHistory] DROP COLUMN [ToStatusId_OLD];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T18:39:09.9091116Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T18:39:09.9091124Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-13T18:39:09.9091127Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260213183913_ConvertEnumsToLookupTables'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260213183913_ConvertEnumsToLookupTables', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214023832_AddShopSuppliesRateToOperatingCosts'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [ShopSuppliesRate] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214023832_AddShopSuppliesRateToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T02:38:28.7266427Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214023832_AddShopSuppliesRateToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T02:38:28.7266433Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214023832_AddShopSuppliesRateToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T02:38:28.7266437Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214023832_AddShopSuppliesRateToOperatingCosts'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260214023832_AddShopSuppliesRateToOperatingCosts', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD [InventoryCategoryId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    CREATE TABLE [InventoryCategoryLookups] (
        [Id] int NOT NULL IDENTITY,
        [CategoryCode] nvarchar(450) NOT NULL,
        [DisplayName] nvarchar(max) NOT NULL,
        [DisplayOrder] int NOT NULL,
        [Description] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [IsSystemDefined] bit NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_InventoryCategoryLookups] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_InventoryCategoryLookups_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T04:18:25.8821520Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T04:18:25.8821525Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T04:18:25.8821527Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN

                    INSERT INTO InventoryCategoryLookups (CategoryCode, DisplayName, DisplayOrder, IsActive, IsSystemDefined, CompanyId, CreatedAt, IsDeleted)
                    SELECT 'POWDER', 'Powder', 1, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                    UNION ALL
                    SELECT 'PRIMER', 'Primer', 2, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                    UNION ALL
                    SELECT 'CLEANER', 'Cleaner', 3, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                    UNION ALL
                    SELECT 'MASKING', 'Masking Supplies', 4, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                    UNION ALL
                    SELECT 'ABRASIVE', 'Abrasive Media', 5, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                    UNION ALL
                    SELECT 'CHEMICAL', 'Chemicals', 6, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                    UNION ALL
                    SELECT 'CONSUMABLE', 'Consumables', 7, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                    UNION ALL
                    SELECT 'TOOL', 'Tools', 8, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                    UNION ALL
                    SELECT 'OTHER', 'Other', 9, 1, 1, c.Id, GETUTCDATE(), 0 FROM Companies c
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN

                    UPDATE i
                    SET i.InventoryCategoryId = c.Id
                    FROM InventoryItems i
                    INNER JOIN InventoryCategoryLookups c ON i.CompanyId = c.CompanyId
                    WHERE i.Category = 'Powder' AND c.CategoryCode = 'POWDER'
                       OR i.Category = 'Primer' AND c.CategoryCode = 'PRIMER'
                       OR i.Category = 'Cleaner' AND c.CategoryCode = 'CLEANER'
                       OR i.Category = 'Masking' AND c.CategoryCode = 'MASKING'
                       OR i.Category = 'Abrasive' AND c.CategoryCode = 'ABRASIVE'
                       OR i.Category = 'Chemical' AND c.CategoryCode = 'CHEMICAL'
                       OR i.Category = 'Consumable' AND c.CategoryCode = 'CONSUMABLE'
                       OR i.Category = 'Tool' AND c.CategoryCode = 'TOOL'
                       OR i.Category = 'Other' AND c.CategoryCode = 'OTHER'
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    CREATE INDEX [IX_InventoryItems_InventoryCategoryId] ON [InventoryItems] ([InventoryCategoryId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    CREATE INDEX [IX_InventoryCategoryLookups_CompanyId] ON [InventoryCategoryLookups] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    CREATE UNIQUE INDEX [IX_InventoryCategoryLookups_CompanyId_CategoryCode] ON [InventoryCategoryLookups] ([CompanyId], [CategoryCode]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD CONSTRAINT [FK_InventoryItems_InventoryCategoryLookups_InventoryCategoryId] FOREIGN KEY ([InventoryCategoryId]) REFERENCES [InventoryCategoryLookups] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214041829_AddInventoryCategoryLookup'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260214041829_AddInventoryCategoryLookup', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214044605_AddIsCoatingToInventoryCategory'
)
BEGIN
    ALTER TABLE [InventoryCategoryLookups] ADD [IsCoating] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214044605_AddIsCoatingToInventoryCategory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T04:46:02.4897150Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214044605_AddIsCoatingToInventoryCategory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T04:46:02.4897155Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214044605_AddIsCoatingToInventoryCategory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T04:46:02.4897157Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214044605_AddIsCoatingToInventoryCategory'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260214044605_AddIsCoatingToInventoryCategory', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214163415_AddQuoteChangeHistory'
)
BEGIN
    CREATE TABLE [QuoteChangeHistories] (
        [Id] int NOT NULL IDENTITY,
        [QuoteId] int NOT NULL,
        [ChangedByUserId] nvarchar(450) NOT NULL,
        [ChangedAt] datetime2 NOT NULL,
        [FieldName] nvarchar(max) NOT NULL,
        [OldValue] nvarchar(max) NULL,
        [NewValue] nvarchar(max) NULL,
        [ChangeDescription] nvarchar(max) NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_QuoteChangeHistories] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_QuoteChangeHistories_AspNetUsers_ChangedByUserId] FOREIGN KEY ([ChangedByUserId]) REFERENCES [AspNetUsers] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_QuoteChangeHistories_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_QuoteChangeHistories_Quotes_QuoteId] FOREIGN KEY ([QuoteId]) REFERENCES [Quotes] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214163415_AddQuoteChangeHistory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T16:34:11.9752246Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214163415_AddQuoteChangeHistory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T16:34:11.9752252Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214163415_AddQuoteChangeHistory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T16:34:11.9752254Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214163415_AddQuoteChangeHistory'
)
BEGIN
    CREATE INDEX [IX_QuoteChangeHistories_ChangedByUserId] ON [QuoteChangeHistories] ([ChangedByUserId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214163415_AddQuoteChangeHistory'
)
BEGIN
    CREATE INDEX [IX_QuoteChangeHistories_CompanyId] ON [QuoteChangeHistories] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214163415_AddQuoteChangeHistory'
)
BEGIN
    CREATE INDEX [IX_QuoteChangeHistories_QuoteId] ON [QuoteChangeHistories] ([QuoteId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214163415_AddQuoteChangeHistory'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260214163415_AddQuoteChangeHistory', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214170954_AddJobChangeHistory'
)
BEGIN
    CREATE TABLE [JobChangeHistories] (
        [Id] int NOT NULL IDENTITY,
        [JobId] int NOT NULL,
        [ChangedByUserId] nvarchar(450) NOT NULL,
        [ChangedAt] datetime2 NOT NULL,
        [FieldName] nvarchar(max) NOT NULL,
        [OldValue] nvarchar(max) NULL,
        [NewValue] nvarchar(max) NULL,
        [ChangeDescription] nvarchar(max) NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobChangeHistories] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobChangeHistories_AspNetUsers_ChangedByUserId] FOREIGN KEY ([ChangedByUserId]) REFERENCES [AspNetUsers] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_JobChangeHistories_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_JobChangeHistories_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214170954_AddJobChangeHistory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T17:09:52.0923949Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214170954_AddJobChangeHistory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T17:09:52.0923957Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214170954_AddJobChangeHistory'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T17:09:52.0923959Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214170954_AddJobChangeHistory'
)
BEGIN
    CREATE INDEX [IX_JobChangeHistories_ChangedByUserId] ON [JobChangeHistories] ([ChangedByUserId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214170954_AddJobChangeHistory'
)
BEGIN
    CREATE INDEX [IX_JobChangeHistories_CompanyId] ON [JobChangeHistories] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214170954_AddJobChangeHistory'
)
BEGIN
    CREATE INDEX [IX_JobChangeHistories_JobId] ON [JobChangeHistories] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214170954_AddJobChangeHistory'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260214170954_AddJobChangeHistory', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214182904_AddMetricSystemPreference'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [UseMetricSystem] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214182904_AddMetricSystemPreference'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T18:29:01.4505899Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214182904_AddMetricSystemPreference'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T18:29:01.4505906Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214182904_AddMetricSystemPreference'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T18:29:01.4505907Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214182904_AddMetricSystemPreference'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260214182904_AddMetricSystemPreference', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    CREATE TABLE [AppointmentStatusLookups] (
        [Id] int NOT NULL IDENTITY,
        [StatusCode] nvarchar(max) NOT NULL,
        [DisplayName] nvarchar(max) NOT NULL,
        [DisplayOrder] int NOT NULL,
        [ColorClass] nvarchar(max) NOT NULL,
        [IconClass] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [IsSystemDefined] bit NOT NULL,
        [IsTerminalStatus] bit NOT NULL,
        [Description] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_AppointmentStatusLookups] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    CREATE TABLE [AppointmentTypeLookups] (
        [Id] int NOT NULL IDENTITY,
        [TypeCode] nvarchar(max) NOT NULL,
        [DisplayName] nvarchar(max) NOT NULL,
        [DisplayOrder] int NOT NULL,
        [ColorClass] nvarchar(max) NOT NULL,
        [IconClass] nvarchar(max) NULL,
        [RequiresJobLink] bit NOT NULL,
        [IsActive] bit NOT NULL,
        [IsSystemDefined] bit NOT NULL,
        [Description] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_AppointmentTypeLookups] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    CREATE TABLE [Appointments] (
        [Id] int NOT NULL IDENTITY,
        [AppointmentNumber] nvarchar(max) NOT NULL,
        [Title] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NULL,
        [CustomerId] int NOT NULL,
        [JobId] int NULL,
        [AppointmentStatusId] int NOT NULL,
        [AppointmentTypeId] int NOT NULL,
        [AssignedWorkerId] int NULL,
        [ScheduledStartTime] datetime2 NOT NULL,
        [ScheduledEndTime] datetime2 NOT NULL,
        [IsAllDay] bit NOT NULL,
        [ActualStartTime] datetime2 NULL,
        [ActualEndTime] datetime2 NULL,
        [Location] nvarchar(max) NULL,
        [Notes] nvarchar(max) NULL,
        [IsReminderEnabled] bit NOT NULL,
        [ReminderMinutesBefore] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Appointments] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Appointments_AppointmentStatusLookups_AppointmentStatusId] FOREIGN KEY ([AppointmentStatusId]) REFERENCES [AppointmentStatusLookups] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_Appointments_AppointmentTypeLookups_AppointmentTypeId] FOREIGN KEY ([AppointmentTypeId]) REFERENCES [AppointmentTypeLookups] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_Appointments_Customers_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [Customers] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_Appointments_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]),
        CONSTRAINT [FK_Appointments_ShopWorkers_AssignedWorkerId] FOREIGN KEY ([AssignedWorkerId]) REFERENCES [ShopWorkers] ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T22:13:31.2633342Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T22:13:31.2633348Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-14T22:13:31.2633349Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    CREATE INDEX [IX_Appointments_AppointmentStatusId] ON [Appointments] ([AppointmentStatusId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    CREATE INDEX [IX_Appointments_AppointmentTypeId] ON [Appointments] ([AppointmentTypeId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    CREATE INDEX [IX_Appointments_AssignedWorkerId] ON [Appointments] ([AssignedWorkerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    CREATE INDEX [IX_Appointments_CustomerId] ON [Appointments] ([CustomerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    CREATE INDEX [IX_Appointments_JobId] ON [Appointments] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260214221334_AddAppointmentScheduling'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260214221334_AddAppointmentScheduling', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215000528_MakeAppointmentCustomerIdOptional'
)
BEGIN
    ALTER TABLE [Appointments] DROP CONSTRAINT [FK_Appointments_Customers_CustomerId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215000528_MakeAppointmentCustomerIdOptional'
)
BEGIN
    DECLARE @var45 sysname;
    SELECT @var45 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Appointments]') AND [c].[name] = N'CustomerId');
    IF @var45 IS NOT NULL EXEC(N'ALTER TABLE [Appointments] DROP CONSTRAINT [' + @var45 + '];');
    ALTER TABLE [Appointments] ALTER COLUMN [CustomerId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215000528_MakeAppointmentCustomerIdOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T00:05:25.6925144Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215000528_MakeAppointmentCustomerIdOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T00:05:25.6925153Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215000528_MakeAppointmentCustomerIdOptional'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T00:05:25.6925155Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215000528_MakeAppointmentCustomerIdOptional'
)
BEGIN
    ALTER TABLE [Appointments] ADD CONSTRAINT [FK_Appointments_Customers_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [Customers] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215000528_MakeAppointmentCustomerIdOptional'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260215000528_MakeAppointmentCustomerIdOptional', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanManageCalendar] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanManageEquipment] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanManageMaintenance] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanManageProducts] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanManageSuppliers] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanViewCalendar] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanViewProducts] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T00:34:41.2332987Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T00:34:41.2332995Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T00:34:41.2332997Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215003444_AddAdditionalUserPermissions'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260215003444_AddAdditionalUserPermissions', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    DROP INDEX [IX_JobPhotos_JobId] ON [JobPhotos];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    DROP INDEX [IX_JobNotes_JobId] ON [JobNotes];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    DROP INDEX [IX_CustomerNotes_CustomerId] ON [CustomerNotes];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T05:05:35.3159644Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T05:05:35.3159650Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T05:05:35.3159652Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Quotes_CompanyId_ExpirationDate] ON [Quotes] ([CompanyId], [ExpirationDate]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Quotes_CompanyId_QuoteStatusId] ON [Quotes] ([CompanyId], [QuoteStatusId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_MaintenanceRecords_CompanyId_ScheduledDate] ON [MaintenanceRecords] ([CompanyId], [ScheduledDate]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_MaintenanceRecords_CompanyId_Status] ON [MaintenanceRecords] ([CompanyId], [Status]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Jobs_CompanyId_CustomerId] ON [Jobs] ([CompanyId], [CustomerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Jobs_CompanyId_DueDate] ON [Jobs] ([CompanyId], [DueDate]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Jobs_CompanyId_JobPriorityId] ON [Jobs] ([CompanyId], [JobPriorityId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Jobs_CompanyId_JobStatusId] ON [Jobs] ([CompanyId], [JobStatusId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Jobs_CompanyId_ScheduledDate] ON [Jobs] ([CompanyId], [ScheduledDate]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_JobPhotos_JobId_IsDeleted_DisplayOrder] ON [JobPhotos] ([JobId], [IsDeleted], [DisplayOrder]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_JobNotes_JobId_CreatedAt] ON [JobNotes] ([JobId], [CreatedAt]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_JobItems_JobId_IsDeleted] ON [JobItems] ([JobId], [IsDeleted]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_InventoryItems_CompanyId_Quantity_Reorder] ON [InventoryItems] ([CompanyId], [QuantityOnHand], [ReorderPoint]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Equipment_CompanyId_Status] ON [Equipment] ([CompanyId], [Status]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_CustomerNotes_CustomerId_CreatedAt] ON [CustomerNotes] ([CustomerId], [CreatedAt]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Appointments_CompanyId_AppointmentStatusId] ON [Appointments] ([CompanyId], [AppointmentStatusId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    CREATE INDEX [IX_Appointments_CompanyId_ScheduledStartTime] ON [Appointments] ([CompanyId], [ScheduledStartTime]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215050538_AddPerformanceIndexes'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260215050538_AddPerformanceIndexes', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    ALTER TABLE [QuoteItems] DROP CONSTRAINT [FK_QuoteItems_InventoryItems_InventoryItemId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    DROP INDEX [IX_QuoteItems_InventoryItemId] ON [QuoteItems];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    DECLARE @var46 sysname;
    SELECT @var46 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'ColorCode');
    IF @var46 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var46 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [ColorCode];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    DECLARE @var47 sysname;
    SELECT @var47 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'ColorName');
    IF @var47 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var47 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [ColorName];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    DECLARE @var48 sysname;
    SELECT @var48 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'Finish');
    IF @var48 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var48 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [Finish];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    DECLARE @var49 sysname;
    SELECT @var49 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'InventoryItemId');
    IF @var49 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var49 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [InventoryItemId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    DECLARE @var50 sysname;
    SELECT @var50 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteItems]') AND [c].[name] = N'PowderCostOverride');
    IF @var50 IS NOT NULL EXEC(N'ALTER TABLE [QuoteItems] DROP CONSTRAINT [' + @var50 + '];');
    ALTER TABLE [QuoteItems] DROP COLUMN [PowderCostOverride];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    CREATE TABLE [QuoteItemCoats] (
        [Id] int NOT NULL IDENTITY,
        [QuoteItemId] int NOT NULL,
        [CoatName] nvarchar(max) NOT NULL,
        [Sequence] int NOT NULL,
        [InventoryItemId] int NULL,
        [ColorName] nvarchar(max) NULL,
        [ColorCode] nvarchar(max) NULL,
        [Finish] nvarchar(max) NULL,
        [CoverageSqFtPerLb] decimal(18,2) NOT NULL,
        [TransferEfficiency] decimal(18,2) NOT NULL,
        [PowderCostPerLb] decimal(18,2) NULL,
        [CoatMaterialCost] decimal(18,2) NOT NULL,
        [CoatLaborCost] decimal(18,2) NOT NULL,
        [CoatTotalCost] decimal(18,2) NOT NULL,
        [Notes] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_QuoteItemCoats] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_QuoteItemCoats_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_QuoteItemCoats_InventoryItems_InventoryItemId] FOREIGN KEY ([InventoryItemId]) REFERENCES [InventoryItems] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_QuoteItemCoats_QuoteItems_QuoteItemId] FOREIGN KEY ([QuoteItemId]) REFERENCES [QuoteItems] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T15:49:00.4799039Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T15:49:00.4799044Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T15:49:00.4799046Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    CREATE INDEX [IX_QuoteItemCoats_CompanyId] ON [QuoteItemCoats] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    CREATE INDEX [IX_QuoteItemCoats_InventoryItemId] ON [QuoteItemCoats] ([InventoryItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    CREATE INDEX [IX_QuoteItemCoats_QuoteItemId] ON [QuoteItemCoats] ([QuoteItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215154903_AddQuoteItemCoatsSupport'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260215154903_AddQuoteItemCoatsSupport', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat'
)
BEGIN
    ALTER TABLE [QuoteItemCoats] ADD [PowderToOrder] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat'
)
BEGIN
    ALTER TABLE [QuoteItemCoats] ADD [SupplierId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T23:06:37.5359459Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T23:06:37.5359465Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T23:06:37.5359467Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat'
)
BEGIN
    CREATE INDEX [IX_QuoteItemCoats_SupplierId] ON [QuoteItemCoats] ([SupplierId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat'
)
BEGIN
    ALTER TABLE [QuoteItemCoats] ADD CONSTRAINT [FK_QuoteItemCoats_Suppliers_SupplierId] FOREIGN KEY ([SupplierId]) REFERENCES [Suppliers] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260215230641_AddPowderToOrderAndSupplierIdToQuoteItemCoat', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215234122_AddAdditionalCoatLaborPercentToOperatingCosts'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [AdditionalCoatLaborPercent] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215234122_AddAdditionalCoatLaborPercentToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T23:41:19.8949787Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215234122_AddAdditionalCoatLaborPercentToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T23:41:19.8949795Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215234122_AddAdditionalCoatLaborPercentToOperatingCosts'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-15T23:41:19.8949841Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260215234122_AddAdditionalCoatLaborPercentToOperatingCosts'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260215234122_AddAdditionalCoatLaborPercentToOperatingCosts', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260216011141_AddInternalNotesToJob'
)
BEGIN
    ALTER TABLE [Jobs] ADD [InternalNotes] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260216011141_AddInternalNotesToJob'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-16T01:11:38.6019819Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260216011141_AddInternalNotesToJob'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-16T01:11:38.6019882Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260216011141_AddInternalNotesToJob'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-16T01:11:38.6019883Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260216011141_AddInternalNotesToJob'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260216011141_AddInternalNotesToJob', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217015314_FixCustomerEmailUniqueIndex'
)
BEGIN
    DROP INDEX [IX_Customers_Email] ON [Customers];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217015314_FixCustomerEmailUniqueIndex'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T01:53:11.9190829Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217015314_FixCustomerEmailUniqueIndex'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T01:53:11.9190834Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217015314_FixCustomerEmailUniqueIndex'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T01:53:11.9190836Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217015314_FixCustomerEmailUniqueIndex'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_Customers_CompanyId_Email] ON [Customers] ([CompanyId], [Email]) WHERE [Email] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217015314_FixCustomerEmailUniqueIndex'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260217015314_FixCustomerEmailUniqueIndex', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    ALTER TABLE [Jobs] ADD [ActualTimeSpentHours] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    CREATE TABLE [JobItemCoats] (
        [Id] int NOT NULL IDENTITY,
        [JobItemId] int NOT NULL,
        [CoatName] nvarchar(max) NOT NULL,
        [Sequence] int NOT NULL,
        [InventoryItemId] int NULL,
        [ColorName] nvarchar(max) NULL,
        [SupplierId] int NULL,
        [ColorCode] nvarchar(max) NULL,
        [Finish] nvarchar(max) NULL,
        [CoverageSqFtPerLb] decimal(18,2) NOT NULL,
        [TransferEfficiency] decimal(18,2) NOT NULL,
        [PowderCostPerLb] decimal(18,2) NULL,
        [PowderToOrder] decimal(18,2) NULL,
        [ActualPowderUsedLbs] decimal(18,2) NULL,
        [Notes] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobItemCoats] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobItemCoats_InventoryItems_InventoryItemId] FOREIGN KEY ([InventoryItemId]) REFERENCES [InventoryItems] ([Id]),
        CONSTRAINT [FK_JobItemCoats_JobItems_JobItemId] FOREIGN KEY ([JobItemId]) REFERENCES [JobItems] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_JobItemCoats_Suppliers_SupplierId] FOREIGN KEY ([SupplierId]) REFERENCES [Suppliers] ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T03:17:51.7026263Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T03:17:51.7026268Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T03:17:51.7026270Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    CREATE INDEX [IX_JobItemCoats_InventoryItemId] ON [JobItemCoats] ([InventoryItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    CREATE INDEX [IX_JobItemCoats_JobItemId] ON [JobItemCoats] ([JobItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    CREATE INDEX [IX_JobItemCoats_SupplierId] ON [JobItemCoats] ([SupplierId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217031754_AddJobItemCoatEntity'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260217031754_AddJobItemCoatEntity', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217052340_AddQuoteDiscountFields'
)
BEGIN
    ALTER TABLE [Quotes] ADD [DiscountReason] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217052340_AddQuoteDiscountFields'
)
BEGIN
    ALTER TABLE [Quotes] ADD [DiscountType] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217052340_AddQuoteDiscountFields'
)
BEGIN
    ALTER TABLE [Quotes] ADD [DiscountValue] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217052340_AddQuoteDiscountFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T05:23:38.1735311Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217052340_AddQuoteDiscountFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T05:23:38.1735344Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217052340_AddQuoteDiscountFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T05:23:38.1735347Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217052340_AddQuoteDiscountFields'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260217052340_AddQuoteDiscountFields', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217170554_AddJobDailyPriority'
)
BEGIN
    CREATE TABLE [JobDailyPriorities] (
        [Id] int NOT NULL IDENTITY,
        [JobId] int NOT NULL,
        [ScheduledDate] datetime2 NOT NULL,
        [DisplayOrder] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobDailyPriorities] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobDailyPriorities_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217170554_AddJobDailyPriority'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T17:05:51.5460473Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217170554_AddJobDailyPriority'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T17:05:51.5460480Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217170554_AddJobDailyPriority'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T17:05:51.5460482Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217170554_AddJobDailyPriority'
)
BEGIN
    CREATE INDEX [IX_JobDailyPriorities_JobId] ON [JobDailyPriorities] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217170554_AddJobDailyPriority'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260217170554_AddJobDailyPriority', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217185430_AddRushJobToQuote'
)
BEGIN
    ALTER TABLE [Quotes] ADD [IsRushJob] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217185430_AddRushJobToQuote'
)
BEGIN
    ALTER TABLE [Quotes] ADD [RushFee] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217185430_AddRushJobToQuote'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T18:54:27.7742836Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217185430_AddRushJobToQuote'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T18:54:27.7742841Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217185430_AddRushJobToQuote'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-17T18:54:27.7742843Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260217185430_AddRushJobToQuote'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260217185430_AddRushJobToQuote', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218004437_AddPrepServicesTable'
)
BEGIN
    CREATE TABLE [PrepServices] (
        [Id] int NOT NULL IDENTITY,
        [ServiceName] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NULL,
        [DisplayOrder] int NOT NULL,
        [IsActive] bit NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_PrepServices] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218004437_AddPrepServicesTable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T00:44:34.4266737Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218004437_AddPrepServicesTable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T00:44:34.4266742Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218004437_AddPrepServicesTable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T00:44:34.4266788Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218004437_AddPrepServicesTable'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260218004437_AddPrepServicesTable', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218010128_AddQuotePrepServiceRelationship'
)
BEGIN
    CREATE TABLE [QuotePrepServices] (
        [Id] int NOT NULL IDENTITY,
        [QuoteId] int NOT NULL,
        [PrepServiceId] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_QuotePrepServices] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_QuotePrepServices_PrepServices_PrepServiceId] FOREIGN KEY ([PrepServiceId]) REFERENCES [PrepServices] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_QuotePrepServices_Quotes_QuoteId] FOREIGN KEY ([QuoteId]) REFERENCES [Quotes] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218010128_AddQuotePrepServiceRelationship'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T01:01:25.3203798Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218010128_AddQuotePrepServiceRelationship'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T01:01:25.3203805Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218010128_AddQuotePrepServiceRelationship'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T01:01:25.3203807Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218010128_AddQuotePrepServiceRelationship'
)
BEGIN
    CREATE INDEX [IX_QuotePrepServices_PrepServiceId] ON [QuotePrepServices] ([PrepServiceId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218010128_AddQuotePrepServiceRelationship'
)
BEGIN
    CREATE INDEX [IX_QuotePrepServices_QuoteId] ON [QuotePrepServices] ([QuoteId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218010128_AddQuotePrepServiceRelationship'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260218010128_AddQuotePrepServiceRelationship', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218012900_AddJobPrepServices'
)
BEGIN
    CREATE TABLE [JobPrepServices] (
        [Id] int NOT NULL IDENTITY,
        [JobId] int NOT NULL,
        [PrepServiceId] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobPrepServices] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobPrepServices_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_JobPrepServices_PrepServices_PrepServiceId] FOREIGN KEY ([PrepServiceId]) REFERENCES [PrepServices] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218012900_AddJobPrepServices'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T01:28:57.6058224Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218012900_AddJobPrepServices'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T01:28:57.6058229Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218012900_AddJobPrepServices'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T01:28:57.6058231Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218012900_AddJobPrepServices'
)
BEGIN
    CREATE INDEX [IX_JobPrepServices_JobId] ON [JobPrepServices] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218012900_AddJobPrepServices'
)
BEGIN
    CREATE INDEX [IX_JobPrepServices_PrepServiceId] ON [JobPrepServices] ([PrepServiceId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218012900_AddJobPrepServices'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260218012900_AddJobPrepServices', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218023413_AddApproximateAreaToCatalogItem'
)
BEGIN
    ALTER TABLE [CatalogItems] ADD [ApproximateArea] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218023413_AddApproximateAreaToCatalogItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T02:34:09.3788277Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218023413_AddApproximateAreaToCatalogItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T02:34:09.3788282Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218023413_AddApproximateAreaToCatalogItem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-18T02:34:09.3788284Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260218023413_AddApproximateAreaToCatalogItem'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260218023413_AddApproximateAreaToCatalogItem', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD [IsRecurring] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD [RecurrenceEndDate] datetime2 NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD [RecurrenceFrequency] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD [RecurrenceGroupId] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD [RecurrenceParentId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-19T14:11:02.7803625Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-19T14:11:02.7803630Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-19T14:11:02.7803632Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    CREATE INDEX [IX_MaintenanceRecords_RecurrenceParentId] ON [MaintenanceRecords] ([RecurrenceParentId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    ALTER TABLE [MaintenanceRecords] ADD CONSTRAINT [FK_MaintenanceRecords_MaintenanceRecords_RecurrenceParentId] FOREIGN KEY ([RecurrenceParentId]) REFERENCES [MaintenanceRecords] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260219141105_AddMaintenanceRecurrence'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260219141105_AddMaintenanceRecurrence', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    ALTER TABLE [Quotes] ADD [OvenCostId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    CREATE TABLE [OvenCosts] (
        [Id] int NOT NULL IDENTITY,
        [Label] nvarchar(100) NOT NULL,
        [CostPerHour] decimal(18,2) NOT NULL,
        [IsActive] bit NOT NULL,
        [DisplayOrder] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_OvenCosts] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_OvenCosts_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-20T17:17:01.4986759Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-20T17:17:01.4986764Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-20T17:17:01.4986765Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    CREATE INDEX [IX_Quotes_OvenCostId] ON [Quotes] ([OvenCostId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    CREATE INDEX [IX_OvenCosts_CompanyId] ON [OvenCosts] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    ALTER TABLE [Quotes] ADD CONSTRAINT [FK_Quotes_OvenCosts_OvenCostId] FOREIGN KEY ([OvenCostId]) REFERENCES [OvenCosts] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260220171704_AddOvenCostTable'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260220171704_AddOvenCostTable', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221001331_AddOvenCostToJobs'
)
BEGIN
    ALTER TABLE [Jobs] ADD [OvenCostId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221001331_AddOvenCostToJobs'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T00:13:27.8500454Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221001331_AddOvenCostToJobs'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T00:13:27.8500462Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221001331_AddOvenCostToJobs'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T00:13:27.8500464Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221001331_AddOvenCostToJobs'
)
BEGIN
    CREATE INDEX [IX_Jobs_OvenCostId] ON [Jobs] ([OvenCostId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221001331_AddOvenCostToJobs'
)
BEGIN
    ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_OvenCosts_OvenCostId] FOREIGN KEY ([OvenCostId]) REFERENCES [OvenCosts] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221001331_AddOvenCostToJobs'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260221001331_AddOvenCostToJobs', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221003434_RemoveProfilePictureDatabaseFields'
)
BEGIN
    DECLARE @var51 sysname;
    SELECT @var51 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[AspNetUsers]') AND [c].[name] = N'ProfilePictureContentType');
    IF @var51 IS NOT NULL EXEC(N'ALTER TABLE [AspNetUsers] DROP CONSTRAINT [' + @var51 + '];');
    ALTER TABLE [AspNetUsers] DROP COLUMN [ProfilePictureContentType];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221003434_RemoveProfilePictureDatabaseFields'
)
BEGIN
    DECLARE @var52 sysname;
    SELECT @var52 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[AspNetUsers]') AND [c].[name] = N'ProfilePictureData');
    IF @var52 IS NOT NULL EXEC(N'ALTER TABLE [AspNetUsers] DROP CONSTRAINT [' + @var52 + '];');
    ALTER TABLE [AspNetUsers] DROP COLUMN [ProfilePictureData];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221003434_RemoveProfilePictureDatabaseFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T00:34:31.8544923Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221003434_RemoveProfilePictureDatabaseFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T00:34:31.8544930Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221003434_RemoveProfilePictureDatabaseFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T00:34:31.8544931Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221003434_RemoveProfilePictureDatabaseFields'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260221003434_RemoveProfilePictureDatabaseFields', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    ALTER TABLE [Customers] ADD [NotifyByEmail] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    ALTER TABLE [Customers] ADD [NotifyBySms] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    CREATE TABLE [NotificationLogs] (
        [Id] int NOT NULL IDENTITY,
        [Channel] int NOT NULL,
        [NotificationType] int NOT NULL,
        [Status] int NOT NULL,
        [RecipientName] nvarchar(max) NOT NULL,
        [Recipient] nvarchar(max) NOT NULL,
        [Subject] nvarchar(max) NULL,
        [Message] nvarchar(max) NOT NULL,
        [ErrorMessage] nvarchar(max) NULL,
        [SentAt] datetime2 NOT NULL,
        [CustomerId] int NULL,
        [JobId] int NULL,
        [QuoteId] int NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_NotificationLogs] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_NotificationLogs_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_NotificationLogs_Customers_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [Customers] ([Id]) ON DELETE SET NULL,
        CONSTRAINT [FK_NotificationLogs_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE SET NULL,
        CONSTRAINT [FK_NotificationLogs_Quotes_QuoteId] FOREIGN KEY ([QuoteId]) REFERENCES [Quotes] ([Id]) ON DELETE SET NULL
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T13:55:37.8574079Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T13:55:37.8574086Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T13:55:37.8574088Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    CREATE INDEX [IX_NotificationLogs_CompanyId_SentAt] ON [NotificationLogs] ([CompanyId], [SentAt]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    CREATE INDEX [IX_NotificationLogs_CompanyId_Status] ON [NotificationLogs] ([CompanyId], [Status]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    CREATE INDEX [IX_NotificationLogs_CustomerId] ON [NotificationLogs] ([CustomerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    CREATE INDEX [IX_NotificationLogs_JobId] ON [NotificationLogs] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    CREATE INDEX [IX_NotificationLogs_QuoteId] ON [NotificationLogs] ([QuoteId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221135541_AddNotificationSystem'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260221135541_AddNotificationSystem', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221141834_AddCustomerUnsubscribeToken'
)
BEGIN
    ALTER TABLE [Customers] ADD [UnsubscribeToken] nvarchar(450) NOT NULL DEFAULT (REPLACE(NEWID(),'-',''));
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221141834_AddCustomerUnsubscribeToken'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T14:18:31.3321750Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221141834_AddCustomerUnsubscribeToken'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T14:18:31.3321756Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221141834_AddCustomerUnsubscribeToken'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T14:18:31.3321758Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221141834_AddCustomerUnsubscribeToken'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Customers_UnsubscribeToken] ON [Customers] ([UnsubscribeToken]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221141834_AddCustomerUnsubscribeToken'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260221141834_AddCustomerUnsubscribeToken', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221232918_AddSmsConsent'
)
BEGIN
    ALTER TABLE [Customers] ADD [SmsConsentMethod] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221232918_AddSmsConsent'
)
BEGIN
    ALTER TABLE [Customers] ADD [SmsConsentedAt] datetime2 NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221232918_AddSmsConsent'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T23:29:14.2199767Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221232918_AddSmsConsent'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T23:29:14.2199772Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221232918_AddSmsConsent'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-21T23:29:14.2199774Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260221232918_AddSmsConsent'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260221232918_AddSmsConsent', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260222133103_AddNotificationTemplates'
)
BEGIN
    CREATE TABLE [NotificationTemplates] (
        [Id] int NOT NULL IDENTITY,
        [NotificationType] int NOT NULL,
        [Channel] int NOT NULL,
        [DisplayName] nvarchar(max) NOT NULL,
        [Subject] nvarchar(max) NULL,
        [Body] nvarchar(max) NOT NULL,
        [IsActive] bit NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_NotificationTemplates] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_NotificationTemplates_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260222133103_AddNotificationTemplates'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-22T13:30:59.4147610Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260222133103_AddNotificationTemplates'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-22T13:30:59.4147617Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260222133103_AddNotificationTemplates'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-22T13:30:59.4147619Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260222133103_AddNotificationTemplates'
)
BEGIN
    CREATE UNIQUE INDEX [IX_NotificationTemplates_Company_Type_Channel] ON [NotificationTemplates] ([CompanyId], [NotificationType], [Channel]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260222133103_AddNotificationTemplates'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260222133103_AddNotificationTemplates', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN

                    IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
                                   WHERE TABLE_NAME = 'CompanyPreferences' AND COLUMN_NAME = 'EmailFromAddress')
                        ALTER TABLE [CompanyPreferences] ADD [EmailFromAddress] nvarchar(max) NULL;
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN

                    IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
                                   WHERE TABLE_NAME = 'CompanyPreferences' AND COLUMN_NAME = 'EmailFromName')
                        ALTER TABLE [CompanyPreferences] ADD [EmailFromName] nvarchar(max) NULL;
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    DECLARE @var53 sysname;
    SELECT @var53 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyPreferences]') AND [c].[name] = N'EmailFromName');
    IF @var53 IS NOT NULL EXEC(N'ALTER TABLE [CompanyPreferences] DROP CONSTRAINT [' + @var53 + '];');
    ALTER TABLE [CompanyPreferences] ALTER COLUMN [EmailFromName] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    DECLARE @var54 sysname;
    SELECT @var54 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyPreferences]') AND [c].[name] = N'EmailFromAddress');
    IF @var54 IS NOT NULL EXEC(N'ALTER TABLE [CompanyPreferences] DROP CONSTRAINT [' + @var54 + '];');
    ALTER TABLE [CompanyPreferences] ALTER COLUMN [EmailFromAddress] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    ALTER TABLE [Companies] ADD [SubscriptionPlanNew] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN

                    UPDATE Companies SET SubscriptionPlanNew =
                        CASE SubscriptionPlan
                            WHEN 'Enterprise' THEN 2
                            WHEN 'Pro' THEN 1
                            WHEN 'Basic' THEN 0
                            ELSE 0
                        END
                
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    DECLARE @var55 sysname;
    SELECT @var55 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Companies]') AND [c].[name] = N'SubscriptionPlan');
    IF @var55 IS NOT NULL EXEC(N'ALTER TABLE [Companies] DROP CONSTRAINT [' + @var55 + '];');
    ALTER TABLE [Companies] DROP COLUMN [SubscriptionPlan];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    EXEC sp_rename N'[Companies].[SubscriptionPlanNew]', N'SubscriptionPlan', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    ALTER TABLE [Companies] ADD [StripeCustomerId] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    ALTER TABLE [Companies] ADD [StripeSubscriptionId] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    ALTER TABLE [Companies] ADD [SubscriptionStatus] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    CREATE TABLE [SubscriptionPlanConfigs] (
        [Id] int NOT NULL IDENTITY,
        [Plan] int NOT NULL,
        [DisplayName] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NULL,
        [MaxUsers] int NOT NULL,
        [MaxActiveJobs] int NOT NULL,
        [MaxCustomers] int NOT NULL,
        [MonthlyPrice] decimal(18,2) NOT NULL,
        [AnnualPrice] decimal(18,2) NOT NULL,
        [StripePriceIdMonthly] nvarchar(max) NULL,
        [StripePriceIdAnnual] nvarchar(max) NULL,
        [IsActive] bit NOT NULL,
        [SortOrder] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_SubscriptionPlanConfigs] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T01:51:32.2577721Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T01:51:32.2577726Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T01:51:32.2577728Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224015135_AddSubscriptionEnumAndStripeFields'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260224015135_AddSubscriptionEnumAndStripeFields', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224035934_AddStarterPlanAndQuoteLimit'
)
BEGIN
    ALTER TABLE [SubscriptionPlanConfigs] ADD [MaxQuotes] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224035934_AddStarterPlanAndQuoteLimit'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T03:59:30.7397881Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224035934_AddStarterPlanAndQuoteLimit'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T03:59:30.7397890Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224035934_AddStarterPlanAndQuoteLimit'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T03:59:30.7397891Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224035934_AddStarterPlanAndQuoteLimit'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260224035934_AddStarterPlanAndQuoteLimit', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224040916_AddCatalogItemLimit'
)
BEGIN
    ALTER TABLE [SubscriptionPlanConfigs] ADD [MaxCatalogItems] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224040916_AddCatalogItemLimit'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T04:09:11.4847911Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224040916_AddCatalogItemLimit'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T04:09:11.4847917Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224040916_AddCatalogItemLimit'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-24T04:09:11.4847919Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260224040916_AddCatalogItemLimit'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260224040916_AddCatalogItemLimit', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225033952_AddGenericQuoteItemFields'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [IsGenericItem] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225033952_AddGenericQuoteItemFields'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [ManualUnitPrice] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225033952_AddGenericQuoteItemFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-25T03:39:48.7901225Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225033952_AddGenericQuoteItemFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-25T03:39:48.7901233Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225033952_AddGenericQuoteItemFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-25T03:39:48.7901234Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225033952_AddGenericQuoteItemFields'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260225033952_AddGenericQuoteItemFields', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [IsLaborItem] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    CREATE TABLE [QuoteItemPrepServices] (
        [Id] int NOT NULL IDENTITY,
        [QuoteItemId] int NOT NULL,
        [PrepServiceId] int NOT NULL,
        [EstimatedMinutes] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_QuoteItemPrepServices] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_QuoteItemPrepServices_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_QuoteItemPrepServices_PrepServices_PrepServiceId] FOREIGN KEY ([PrepServiceId]) REFERENCES [PrepServices] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_QuoteItemPrepServices_QuoteItems_QuoteItemId] FOREIGN KEY ([QuoteItemId]) REFERENCES [QuoteItems] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-25T13:51:28.7925967Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-25T13:51:28.7925974Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-25T13:51:28.7925975Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    CREATE INDEX [IX_QuoteItemPrepServices_CompanyId] ON [QuoteItemPrepServices] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    CREATE INDEX [IX_QuoteItemPrepServices_PrepServiceId] ON [QuoteItemPrepServices] ([PrepServiceId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    CREATE INDEX [IX_QuoteItemPrepServices_QuoteItemId] ON [QuoteItemPrepServices] ([QuoteItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260225135132_AddQuoteItemPrepServices'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260225135132_AddQuoteItemPrepServices', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany'
)
BEGIN
    DROP INDEX [IX_Quotes_QuoteNumber] ON [Quotes];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany'
)
BEGIN
    DROP INDEX [IX_Jobs_JobNumber] ON [Jobs];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-26T17:16:01.0942463Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-26T17:16:01.0942470Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-26T17:16:01.0942471Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Quotes_CompanyId_QuoteNumber] ON [Quotes] ([CompanyId], [QuoteNumber]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Jobs_CompanyId_JobNumber] ON [Jobs] ([CompanyId], [JobNumber]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260226171604_FixJobQuoteNumberUniqueIndexPerCompany', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227020607_RemoveSubscriptionPlanEnum'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-27T02:06:03.2426692Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227020607_RemoveSubscriptionPlanEnum'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-27T02:06:03.2426696Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227020607_RemoveSubscriptionPlanEnum'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-27T02:06:03.2426698Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227020607_RemoveSubscriptionPlanEnum'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260227020607_RemoveSubscriptionPlanEnum', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227042457_AddBugReports'
)
BEGIN
    CREATE TABLE [BugReports] (
        [Id] int NOT NULL IDENTITY,
        [Title] nvarchar(max) NOT NULL,
        [Description] nvarchar(max) NOT NULL,
        [SubmittedByUserId] nvarchar(max) NOT NULL,
        [SubmittedByUserName] nvarchar(max) NOT NULL,
        [Priority] int NOT NULL,
        [Status] int NOT NULL,
        [ResolutionNotes] nvarchar(max) NULL,
        [ResolvedAt] datetime2 NULL,
        [ResolvedBy] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_BugReports] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227042457_AddBugReports'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-27T04:24:54.3532986Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227042457_AddBugReports'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-27T04:24:54.3532991Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227042457_AddBugReports'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-02-27T04:24:54.3532993Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260227042457_AddBugReports'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260227042457_AddBugReports', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260302003433_AddMaxJobPhotosToSubscriptionPlanConfig'
)
BEGIN
    ALTER TABLE [SubscriptionPlanConfigs] ADD [MaxJobPhotos] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260302003433_AddMaxJobPhotosToSubscriptionPlanConfig'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-02T00:34:29.7591703Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260302003433_AddMaxJobPhotosToSubscriptionPlanConfig'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-02T00:34:29.7591710Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260302003433_AddMaxJobPhotosToSubscriptionPlanConfig'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-02T00:34:29.7591711Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260302003433_AddMaxJobPhotosToSubscriptionPlanConfig'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260302003433_AddMaxJobPhotosToSubscriptionPlanConfig', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [QtAccentColor] nvarchar(max) NOT NULL DEFAULT N'';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [QtDefaultTerms] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [QtFooterNote] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [QtShowDetailedBreakdown] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [QtShowPreparedBy] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-04T01:41:22.4363124Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-04T01:41:22.4363129Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-04T01:41:22.4363130Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304014125_AddQuoteTemplateToCompanyPreferences'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260304014125_AddQuoteTemplateToCompanyPreferences', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304030757_RemoveQuotePdfToggleColumns'
)
BEGIN
    DECLARE @var56 sysname;
    SELECT @var56 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyPreferences]') AND [c].[name] = N'QtShowDetailedBreakdown');
    IF @var56 IS NOT NULL EXEC(N'ALTER TABLE [CompanyPreferences] DROP CONSTRAINT [' + @var56 + '];');
    ALTER TABLE [CompanyPreferences] DROP COLUMN [QtShowDetailedBreakdown];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304030757_RemoveQuotePdfToggleColumns'
)
BEGIN
    DECLARE @var57 sysname;
    SELECT @var57 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyPreferences]') AND [c].[name] = N'QtShowPreparedBy');
    IF @var57 IS NOT NULL EXEC(N'ALTER TABLE [CompanyPreferences] DROP CONSTRAINT [' + @var57 + '];');
    ALTER TABLE [CompanyPreferences] DROP COLUMN [QtShowPreparedBy];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304030757_RemoveQuotePdfToggleColumns'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-04T03:07:54.3122285Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304030757_RemoveQuotePdfToggleColumns'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-04T03:07:54.3122290Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304030757_RemoveQuotePdfToggleColumns'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-04T03:07:54.3122291Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260304030757_RemoveQuotePdfToggleColumns'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260304030757_RemoveQuotePdfToggleColumns', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    CREATE TABLE [Announcements] (
        [Id] int NOT NULL IDENTITY,
        [Title] nvarchar(max) NOT NULL,
        [Message] nvarchar(max) NOT NULL,
        [Type] nvarchar(max) NOT NULL,
        [Target] nvarchar(max) NOT NULL,
        [TargetPlan] int NULL,
        [TargetCompanyId] int NULL,
        [StartsAt] datetime2 NOT NULL,
        [ExpiresAt] datetime2 NULL,
        [IsDismissible] bit NOT NULL,
        [IsActive] bit NOT NULL,
        [CreatedByUserId] nvarchar(max) NOT NULL,
        [CreatedByUserName] nvarchar(max) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        CONSTRAINT [PK_Announcements] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    CREATE TABLE [AuditLogs] (
        [Id] bigint NOT NULL IDENTITY,
        [UserId] nvarchar(max) NULL,
        [UserName] nvarchar(max) NOT NULL,
        [CompanyId] int NULL,
        [CompanyName] nvarchar(max) NULL,
        [Action] nvarchar(max) NOT NULL,
        [EntityType] nvarchar(450) NOT NULL,
        [EntityId] nvarchar(450) NULL,
        [EntityDescription] nvarchar(max) NULL,
        [OldValues] nvarchar(max) NULL,
        [NewValues] nvarchar(max) NULL,
        [IpAddress] nvarchar(max) NULL,
        [Timestamp] datetime2 NOT NULL,
        CONSTRAINT [PK_AuditLogs] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    CREATE TABLE [AnnouncementDismissals] (
        [Id] int NOT NULL IDENTITY,
        [AnnouncementId] int NOT NULL,
        [UserId] nvarchar(450) NOT NULL,
        [DismissedAt] datetime2 NOT NULL,
        CONSTRAINT [PK_AnnouncementDismissals] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_AnnouncementDismissals_Announcements_AnnouncementId] FOREIGN KEY ([AnnouncementId]) REFERENCES [Announcements] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T15:19:18.4239141Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T15:19:18.4239145Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T15:19:18.4239147Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    CREATE UNIQUE INDEX [IX_AnnouncementDismissals_AnnouncementId_UserId] ON [AnnouncementDismissals] ([AnnouncementId], [UserId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    CREATE INDEX [IX_AuditLogs_CompanyId_Timestamp] ON [AuditLogs] ([CompanyId], [Timestamp]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    CREATE INDEX [IX_AuditLogs_EntityType_EntityId] ON [AuditLogs] ([EntityType], [EntityId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305151921_AddAuditLogsAndAnnouncements'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260305151921_AddAuditLogsAndAnnouncements', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    ALTER TABLE [Companies] ADD [IsComped] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    ALTER TABLE [Companies] ADD [MaxActiveJobsOverride] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    ALTER TABLE [Companies] ADD [MaxCatalogItemsOverride] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    ALTER TABLE [Companies] ADD [MaxCustomersOverride] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    ALTER TABLE [Companies] ADD [MaxJobPhotosOverride] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    ALTER TABLE [Companies] ADD [MaxQuotesOverride] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    ALTER TABLE [Companies] ADD [MaxUsersOverride] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    ALTER TABLE [Companies] ADD [SubscriptionNotes] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T15:33:19.1489947Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T15:33:19.1489951Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T15:33:19.1489953Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305153322_AddCompanyCompedAndOverrides'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260305153322_AddCompanyCompedAndOverrides', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305162820_AddReleaseNotes'
)
BEGIN
    CREATE TABLE [ReleaseNotes] (
        [Id] int NOT NULL IDENTITY,
        [Version] nvarchar(max) NOT NULL,
        [Title] nvarchar(max) NOT NULL,
        [Body] nvarchar(max) NOT NULL,
        [Tag] nvarchar(max) NOT NULL,
        [IsPublished] bit NOT NULL,
        [ReleasedAt] datetime2 NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedByUserId] nvarchar(max) NULL,
        [CreatedByUserName] nvarchar(max) NULL,
        CONSTRAINT [PK_ReleaseNotes] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305162820_AddReleaseNotes'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T16:28:17.1220446Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305162820_AddReleaseNotes'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T16:28:17.1220451Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305162820_AddReleaseNotes'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-05T16:28:17.1220452Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260305162820_AddReleaseNotes'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260305162820_AddReleaseNotes', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306005902_AddNotifyOnNewQuote'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [NotifyOnNewQuote] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306005902_AddNotifyOnNewQuote'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T00:58:59.0297641Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306005902_AddNotifyOnNewQuote'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T00:58:59.0297648Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306005902_AddNotifyOnNewQuote'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T00:58:59.0297650Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306005902_AddNotifyOnNewQuote'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260306005902_AddNotifyOnNewQuote', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    ALTER TABLE [NotificationLogs] ADD [InvoiceId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE TABLE [Invoices] (
        [Id] int NOT NULL IDENTITY,
        [InvoiceNumber] nvarchar(450) NOT NULL,
        [JobId] int NOT NULL,
        [CustomerId] int NOT NULL,
        [PreparedById] nvarchar(450) NULL,
        [Status] int NOT NULL,
        [InvoiceDate] datetime2 NOT NULL,
        [DueDate] datetime2 NULL,
        [SentDate] datetime2 NULL,
        [PaidDate] datetime2 NULL,
        [SubTotal] decimal(18,2) NOT NULL,
        [TaxPercent] decimal(18,2) NOT NULL,
        [TaxAmount] decimal(18,2) NOT NULL,
        [DiscountAmount] decimal(18,2) NOT NULL,
        [Total] decimal(18,2) NOT NULL,
        [AmountPaid] decimal(18,2) NOT NULL,
        [Notes] nvarchar(max) NULL,
        [InternalNotes] nvarchar(max) NULL,
        [Terms] nvarchar(max) NULL,
        [CustomerPO] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Invoices] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Invoices_AspNetUsers_PreparedById] FOREIGN KEY ([PreparedById]) REFERENCES [AspNetUsers] ([Id]) ON DELETE SET NULL,
        CONSTRAINT [FK_Invoices_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_Invoices_Customers_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [Customers] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_Invoices_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE TABLE [InvoiceItems] (
        [Id] int NOT NULL IDENTITY,
        [InvoiceId] int NOT NULL,
        [SourceJobItemId] int NULL,
        [Description] nvarchar(max) NOT NULL,
        [Quantity] decimal(18,2) NOT NULL,
        [UnitPrice] decimal(18,2) NOT NULL,
        [TotalPrice] decimal(18,2) NOT NULL,
        [ColorName] nvarchar(max) NULL,
        [Notes] nvarchar(max) NULL,
        [DisplayOrder] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_InvoiceItems] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_InvoiceItems_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_InvoiceItems_Invoices_InvoiceId] FOREIGN KEY ([InvoiceId]) REFERENCES [Invoices] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_InvoiceItems_JobItems_SourceJobItemId] FOREIGN KEY ([SourceJobItemId]) REFERENCES [JobItems] ([Id]) ON DELETE SET NULL
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE TABLE [Payments] (
        [Id] int NOT NULL IDENTITY,
        [InvoiceId] int NOT NULL,
        [Amount] decimal(18,2) NOT NULL,
        [PaymentDate] datetime2 NOT NULL,
        [PaymentMethod] int NOT NULL,
        [Reference] nvarchar(max) NULL,
        [Notes] nvarchar(max) NULL,
        [RecordedById] nvarchar(450) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Payments] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Payments_AspNetUsers_RecordedById] FOREIGN KEY ([RecordedById]) REFERENCES [AspNetUsers] ([Id]) ON DELETE SET NULL,
        CONSTRAINT [FK_Payments_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_Payments_Invoices_InvoiceId] FOREIGN KEY ([InvoiceId]) REFERENCES [Invoices] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T01:52:29.1309651Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T01:52:29.1309658Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T01:52:29.1309659Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_NotificationLogs_InvoiceId] ON [NotificationLogs] ([InvoiceId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_InvoiceItems_CompanyId] ON [InvoiceItems] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_InvoiceItems_InvoiceId] ON [InvoiceItems] ([InvoiceId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_InvoiceItems_SourceJobItemId] ON [InvoiceItems] ([SourceJobItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_Invoices_CompanyId_CustomerId] ON [Invoices] ([CompanyId], [CustomerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_Invoices_CompanyId_DueDate] ON [Invoices] ([CompanyId], [DueDate]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Invoices_CompanyId_InvoiceNumber] ON [Invoices] ([CompanyId], [InvoiceNumber]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Invoices_CompanyId_JobId] ON [Invoices] ([CompanyId], [JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_Invoices_CompanyId_Status] ON [Invoices] ([CompanyId], [Status]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_Invoices_CustomerId] ON [Invoices] ([CustomerId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE UNIQUE INDEX [IX_Invoices_JobId] ON [Invoices] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_Invoices_PreparedById] ON [Invoices] ([PreparedById]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_Payments_CompanyId_PaymentDate] ON [Payments] ([CompanyId], [PaymentDate]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_Payments_InvoiceId] ON [Payments] ([InvoiceId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    CREATE INDEX [IX_Payments_RecordedById] ON [Payments] ([RecordedById]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    ALTER TABLE [NotificationLogs] ADD CONSTRAINT [FK_NotificationLogs_Invoices_InvoiceId] FOREIGN KEY ([InvoiceId]) REFERENCES [Invoices] ([Id]) ON DELETE SET NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306015232_AddInvoicesAndPayments'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260306015232_AddInvoicesAndPayments', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [CurrentBalance] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [DefaultExpenseAccountId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [OpeningBalance] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    ALTER TABLE [Suppliers] ADD [OpeningBalanceDate] datetime2 NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE TABLE [Accounts] (
        [Id] int NOT NULL IDENTITY,
        [AccountNumber] nvarchar(max) NOT NULL,
        [Name] nvarchar(max) NOT NULL,
        [AccountType] int NOT NULL,
        [AccountSubType] int NOT NULL,
        [Description] nvarchar(max) NULL,
        [ParentAccountId] int NULL,
        [IsSystem] bit NOT NULL,
        [IsActive] bit NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Accounts] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Accounts_Accounts_ParentAccountId] FOREIGN KEY ([ParentAccountId]) REFERENCES [Accounts] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE TABLE [Bills] (
        [Id] int NOT NULL IDENTITY,
        [BillNumber] nvarchar(max) NOT NULL,
        [SupplierInvoiceNumber] nvarchar(max) NULL,
        [SupplierId] int NOT NULL,
        [APAccountId] int NOT NULL,
        [BillDate] datetime2 NOT NULL,
        [DueDate] datetime2 NULL,
        [Status] int NOT NULL,
        [Terms] nvarchar(max) NULL,
        [Memo] nvarchar(max) NULL,
        [SubTotal] decimal(18,2) NOT NULL,
        [TaxPercent] decimal(18,2) NOT NULL,
        [TaxAmount] decimal(18,2) NOT NULL,
        [Total] decimal(18,2) NOT NULL,
        [AmountPaid] decimal(18,2) NOT NULL,
        [BalanceDue] decimal(18,2) NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Bills] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Bills_Accounts_APAccountId] FOREIGN KEY ([APAccountId]) REFERENCES [Accounts] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_Bills_Suppliers_SupplierId] FOREIGN KEY ([SupplierId]) REFERENCES [Suppliers] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE TABLE [Expenses] (
        [Id] int NOT NULL IDENTITY,
        [ExpenseNumber] nvarchar(max) NOT NULL,
        [Date] datetime2 NOT NULL,
        [SupplierId] int NULL,
        [ExpenseAccountId] int NOT NULL,
        [PaymentAccountId] int NOT NULL,
        [JobId] int NULL,
        [PaymentMethod] int NOT NULL,
        [Amount] decimal(18,2) NOT NULL,
        [Memo] nvarchar(max) NULL,
        [ReceiptFilePath] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_Expenses] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Expenses_Accounts_ExpenseAccountId] FOREIGN KEY ([ExpenseAccountId]) REFERENCES [Accounts] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_Expenses_Accounts_PaymentAccountId] FOREIGN KEY ([PaymentAccountId]) REFERENCES [Accounts] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_Expenses_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id]),
        CONSTRAINT [FK_Expenses_Suppliers_SupplierId] FOREIGN KEY ([SupplierId]) REFERENCES [Suppliers] ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE TABLE [BillLineItems] (
        [Id] int NOT NULL IDENTITY,
        [BillId] int NOT NULL,
        [AccountId] int NOT NULL,
        [JobId] int NULL,
        [Description] nvarchar(max) NOT NULL,
        [Quantity] decimal(18,2) NOT NULL,
        [UnitPrice] decimal(18,2) NOT NULL,
        [Amount] decimal(18,2) NOT NULL,
        [DisplayOrder] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_BillLineItems] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_BillLineItems_Accounts_AccountId] FOREIGN KEY ([AccountId]) REFERENCES [Accounts] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_BillLineItems_Bills_BillId] FOREIGN KEY ([BillId]) REFERENCES [Bills] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_BillLineItems_Jobs_JobId] FOREIGN KEY ([JobId]) REFERENCES [Jobs] ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE TABLE [BillPayments] (
        [Id] int NOT NULL IDENTITY,
        [PaymentNumber] nvarchar(max) NOT NULL,
        [BillId] int NOT NULL,
        [SupplierId] int NOT NULL,
        [BankAccountId] int NOT NULL,
        [PaymentDate] datetime2 NOT NULL,
        [Amount] decimal(18,2) NOT NULL,
        [PaymentMethod] int NOT NULL,
        [CheckNumber] nvarchar(max) NULL,
        [Memo] nvarchar(max) NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_BillPayments] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_BillPayments_Accounts_BankAccountId] FOREIGN KEY ([BankAccountId]) REFERENCES [Accounts] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_BillPayments_Bills_BillId] FOREIGN KEY ([BillId]) REFERENCES [Bills] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_BillPayments_Suppliers_SupplierId] FOREIGN KEY ([SupplierId]) REFERENCES [Suppliers] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T14:46:17.1798908Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T14:46:17.1798917Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-06T14:46:17.1798919Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_Suppliers_DefaultExpenseAccountId] ON [Suppliers] ([DefaultExpenseAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_Accounts_ParentAccountId] ON [Accounts] ([ParentAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_BillLineItems_AccountId] ON [BillLineItems] ([AccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_BillLineItems_BillId] ON [BillLineItems] ([BillId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_BillLineItems_JobId] ON [BillLineItems] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_BillPayments_BankAccountId] ON [BillPayments] ([BankAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_BillPayments_BillId] ON [BillPayments] ([BillId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_BillPayments_SupplierId] ON [BillPayments] ([SupplierId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_Bills_APAccountId] ON [Bills] ([APAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_Bills_SupplierId] ON [Bills] ([SupplierId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_Expenses_ExpenseAccountId] ON [Expenses] ([ExpenseAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_Expenses_JobId] ON [Expenses] ([JobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_Expenses_PaymentAccountId] ON [Expenses] ([PaymentAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    CREATE INDEX [IX_Expenses_SupplierId] ON [Expenses] ([SupplierId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    ALTER TABLE [Suppliers] ADD CONSTRAINT [FK_Suppliers_Accounts_DefaultExpenseAccountId] FOREIGN KEY ([DefaultExpenseAccountId]) REFERENCES [Accounts] ([Id]) ON DELETE SET NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260306144620_AddExpenseTracking'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260306144620_AddExpenseTracking', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307025253_AddOvenBatchPricing'
)
BEGIN
    ALTER TABLE [Quotes] ADD [OvenBatches] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307025253_AddOvenBatchPricing'
)
BEGIN
    ALTER TABLE [Quotes] ADD [OvenCycleMinutes] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307025253_AddOvenBatchPricing'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [DefaultOvenCycleMinutes] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307025253_AddOvenBatchPricing'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-07T02:52:50.0213171Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307025253_AddOvenBatchPricing'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-07T02:52:50.0213179Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307025253_AddOvenBatchPricing'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-07T02:52:50.0213180Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307025253_AddOvenBatchPricing'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260307025253_AddOvenBatchPricing', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    ALTER TABLE [JobItems] ADD [CatalogItemId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    ALTER TABLE [JobItems] ADD [IncludePrepCost] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    ALTER TABLE [JobItems] ADD [IsGenericItem] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    ALTER TABLE [JobItems] ADD [IsLaborItem] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    ALTER TABLE [JobItems] ADD [ManualUnitPrice] decimal(18,2) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    ALTER TABLE [JobItems] ADD [SurfaceAreaSqFt] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    CREATE TABLE [JobItemPrepServices] (
        [Id] int NOT NULL IDENTITY,
        [JobItemId] int NOT NULL,
        [PrepServiceId] int NOT NULL,
        [EstimatedMinutes] int NOT NULL,
        [CompanyId] int NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [UpdatedAt] datetime2 NULL,
        [CreatedBy] nvarchar(max) NULL,
        [UpdatedBy] nvarchar(max) NULL,
        [IsDeleted] bit NOT NULL,
        [DeletedAt] datetime2 NULL,
        [DeletedBy] nvarchar(max) NULL,
        CONSTRAINT [PK_JobItemPrepServices] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_JobItemPrepServices_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_JobItemPrepServices_JobItems_JobItemId] FOREIGN KEY ([JobItemId]) REFERENCES [JobItems] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_JobItemPrepServices_PrepServices_PrepServiceId] FOREIGN KEY ([PrepServiceId]) REFERENCES [PrepServices] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-07T04:22:49.7694725Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-07T04:22:49.7694732Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-07T04:22:49.7694733Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    CREATE INDEX [IX_JobItems_CatalogItemId] ON [JobItems] ([CatalogItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    CREATE INDEX [IX_JobItemPrepServices_CompanyId] ON [JobItemPrepServices] ([CompanyId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    CREATE INDEX [IX_JobItemPrepServices_JobItemId] ON [JobItemPrepServices] ([JobItemId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    CREATE INDEX [IX_JobItemPrepServices_PrepServiceId] ON [JobItemPrepServices] ([PrepServiceId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    ALTER TABLE [JobItems] ADD CONSTRAINT [FK_JobItems_CatalogItems_CatalogItemId] FOREIGN KEY ([CatalogItemId]) REFERENCES [CatalogItems] ([Id]) ON DELETE SET NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260307042253_AddJobItemPrepServiceAndFields'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260307042253_AddJobItemPrepServiceAndFields', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    ALTER TABLE [CatalogItems] ADD [CogsAccountId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    ALTER TABLE [CatalogItems] ADD [RevenueAccountId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:25:04.4858995Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:25:04.4859001Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:25:04.4859002Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    CREATE INDEX [IX_CatalogItems_CogsAccountId] ON [CatalogItems] ([CogsAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    CREATE INDEX [IX_CatalogItems_RevenueAccountId] ON [CatalogItems] ([RevenueAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    ALTER TABLE [CatalogItems] ADD CONSTRAINT [FK_CatalogItems_Accounts_CogsAccountId] FOREIGN KEY ([CogsAccountId]) REFERENCES [Accounts] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    ALTER TABLE [CatalogItems] ADD CONSTRAINT [FK_CatalogItems_Accounts_RevenueAccountId] FOREIGN KEY ([RevenueAccountId]) REFERENCES [Accounts] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308032507_AddCatalogItemAccountMapping'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308032507_AddCatalogItemAccountMapping', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD [CogsAccountId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD [InventoryAccountId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:32:08.1164268Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:32:08.1164274Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:32:08.1164275Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    CREATE INDEX [IX_InventoryItems_CogsAccountId] ON [InventoryItems] ([CogsAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    CREATE INDEX [IX_InventoryItems_InventoryAccountId] ON [InventoryItems] ([InventoryAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD CONSTRAINT [FK_InventoryItems_Accounts_CogsAccountId] FOREIGN KEY ([CogsAccountId]) REFERENCES [Accounts] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD CONSTRAINT [FK_InventoryItems_Accounts_InventoryAccountId] FOREIGN KEY ([InventoryAccountId]) REFERENCES [Accounts] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033211_AddInventoryItemAccountMapping'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308033211_AddInventoryItemAccountMapping', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033945_AddInvoiceItemRevenueAccount'
)
BEGIN
    ALTER TABLE [InvoiceItems] ADD [RevenueAccountId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033945_AddInvoiceItemRevenueAccount'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:39:41.9745262Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033945_AddInvoiceItemRevenueAccount'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:39:41.9745268Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033945_AddInvoiceItemRevenueAccount'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:39:41.9745293Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033945_AddInvoiceItemRevenueAccount'
)
BEGIN
    CREATE INDEX [IX_InvoiceItems_RevenueAccountId] ON [InvoiceItems] ([RevenueAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033945_AddInvoiceItemRevenueAccount'
)
BEGIN
    ALTER TABLE [InvoiceItems] ADD CONSTRAINT [FK_InvoiceItems_Accounts_RevenueAccountId] FOREIGN KEY ([RevenueAccountId]) REFERENCES [Accounts] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308033945_AddInvoiceItemRevenueAccount'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308033945_AddInvoiceItemRevenueAccount', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    ALTER TABLE [Payments] ADD [DepositAccountId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    ALTER TABLE [Invoices] ADD [SalesTaxAccountId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:45:54.4068622Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:45:54.4068628Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T03:45:54.4068630Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    CREATE INDEX [IX_Payments_DepositAccountId] ON [Payments] ([DepositAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    CREATE INDEX [IX_Invoices_SalesTaxAccountId] ON [Invoices] ([SalesTaxAccountId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    ALTER TABLE [Invoices] ADD CONSTRAINT [FK_Invoices_Accounts_SalesTaxAccountId] FOREIGN KEY ([SalesTaxAccountId]) REFERENCES [Accounts] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    ALTER TABLE [Payments] ADD CONSTRAINT [FK_Payments_Accounts_DepositAccountId] FOREIGN KEY ([DepositAccountId]) REFERENCES [Accounts] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308034557_AddPaymentDepositAndInvoiceSalesTax'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308034557_AddPaymentDepositAndInvoiceSalesTax', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [BillPayments] DROP CONSTRAINT [FK_BillPayments_Suppliers_SupplierId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [Bills] DROP CONSTRAINT [FK_Bills_Suppliers_SupplierId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [Expenses] DROP CONSTRAINT [FK_Expenses_Suppliers_SupplierId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [InventoryItems] DROP CONSTRAINT [FK_InventoryItems_Suppliers_PrimarySupplierId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [JobItemCoats] DROP CONSTRAINT [FK_JobItemCoats_Suppliers_SupplierId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [QuoteItemCoats] DROP CONSTRAINT [FK_QuoteItemCoats_Suppliers_SupplierId];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[Suppliers]', N'Vendors';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[Vendors].[IX_Suppliers_CompanyId]', N'IX_Vendors_CompanyId', N'INDEX';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[Vendors].[IX_Suppliers_DefaultExpenseAccountId]', N'IX_Vendors_DefaultExpenseAccountId', N'INDEX';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[QuoteItemCoats].[SupplierId]', N'VendorId', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[QuoteItemCoats].[IX_QuoteItemCoats_SupplierId]', N'IX_QuoteItemCoats_VendorId', N'INDEX';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[JobItemCoats].[SupplierId]', N'VendorId', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[JobItemCoats].[IX_JobItemCoats_SupplierId]', N'IX_JobItemCoats_VendorId', N'INDEX';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[InventoryItems].[SupplierPartNumber]', N'VendorPartNumber', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[InventoryItems].[PrimarySupplierId]', N'PrimaryVendorId', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[InventoryItems].[IX_InventoryItems_PrimarySupplierId]', N'IX_InventoryItems_PrimaryVendorId', N'INDEX';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[Expenses].[SupplierId]', N'VendorId', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[Expenses].[IX_Expenses_SupplierId]', N'IX_Expenses_VendorId', N'INDEX';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[Bills].[SupplierInvoiceNumber]', N'VendorInvoiceNumber', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[Bills].[SupplierId]', N'VendorId', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[Bills].[IX_Bills_SupplierId]', N'IX_Bills_VendorId', N'INDEX';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[BillPayments].[SupplierId]', N'VendorId', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[BillPayments].[IX_BillPayments_SupplierId]', N'IX_BillPayments_VendorId', N'INDEX';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC sp_rename N'[AspNetUsers].[CanManageSuppliers]', N'CanManageVendors', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T04:31:35.0987168Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T04:31:35.0987176Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T04:31:35.0987177Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [BillPayments] ADD CONSTRAINT [FK_BillPayments_Vendors_VendorId] FOREIGN KEY ([VendorId]) REFERENCES [Vendors] ([Id]) ON DELETE NO ACTION;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [Bills] ADD CONSTRAINT [FK_Bills_Vendors_VendorId] FOREIGN KEY ([VendorId]) REFERENCES [Vendors] ([Id]) ON DELETE CASCADE;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [Expenses] ADD CONSTRAINT [FK_Expenses_Vendors_VendorId] FOREIGN KEY ([VendorId]) REFERENCES [Vendors] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [InventoryItems] ADD CONSTRAINT [FK_InventoryItems_Vendors_PrimaryVendorId] FOREIGN KEY ([PrimaryVendorId]) REFERENCES [Vendors] ([Id]) ON DELETE SET NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [JobItemCoats] ADD CONSTRAINT [FK_JobItemCoats_Vendors_VendorId] FOREIGN KEY ([VendorId]) REFERENCES [Vendors] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    ALTER TABLE [QuoteItemCoats] ADD CONSTRAINT [FK_QuoteItemCoats_Vendors_VendorId] FOREIGN KEY ([VendorId]) REFERENCES [Vendors] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308043138_RenameSupplierToVendor'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308043138_RenameSupplierToVendor', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308150847_AddInvoicesAndReportsPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanManageInvoices] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308150847_AddInvoicesAndReportsPermissions'
)
BEGIN
    ALTER TABLE [AspNetUsers] ADD [CanViewReports] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308150847_AddInvoicesAndReportsPermissions'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T15:08:44.4862369Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308150847_AddInvoicesAndReportsPermissions'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T15:08:44.4862381Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308150847_AddInvoicesAndReportsPermissions'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T15:08:44.4862383Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308150847_AddInvoicesAndReportsPermissions'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308150847_AddInvoicesAndReportsPermissions', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308155838_AddAccountOpeningBalance'
)
BEGIN
    ALTER TABLE [Accounts] ADD [OpeningBalance] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308155838_AddAccountOpeningBalance'
)
BEGIN
    ALTER TABLE [Accounts] ADD [OpeningBalanceDate] datetime2 NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308155838_AddAccountOpeningBalance'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T15:58:34.6413623Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308155838_AddAccountOpeningBalance'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T15:58:34.6413629Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308155838_AddAccountOpeningBalance'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T15:58:34.6413631Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308155838_AddAccountOpeningBalance'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308155838_AddAccountOpeningBalance', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308195919_AddSetupWizardProgress'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [SetupWizardCompleted] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308195919_AddSetupWizardProgress'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [SetupWizardDoneSteps] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308195919_AddSetupWizardProgress'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [SetupWizardSkippedSteps] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308195919_AddSetupWizardProgress'
)
BEGIN
    ALTER TABLE [CompanyPreferences] ADD [SetupWizardStarted] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308195919_AddSetupWizardProgress'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T19:59:16.5982808Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308195919_AddSetupWizardProgress'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T19:59:16.5982817Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308195919_AddSetupWizardProgress'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T19:59:16.5982819Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308195919_AddSetupWizardProgress'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308195919_AddSetupWizardProgress', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308212530_RemoveSandblastingMaskingStepFlags'
)
BEGIN
    DECLARE @var58 sysname;
    SELECT @var58 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyPreferences]') AND [c].[name] = N'EnableMaskingStep');
    IF @var58 IS NOT NULL EXEC(N'ALTER TABLE [CompanyPreferences] DROP CONSTRAINT [' + @var58 + '];');
    ALTER TABLE [CompanyPreferences] DROP COLUMN [EnableMaskingStep];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308212530_RemoveSandblastingMaskingStepFlags'
)
BEGIN
    DECLARE @var59 sysname;
    SELECT @var59 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[CompanyPreferences]') AND [c].[name] = N'EnableSandblastingStep');
    IF @var59 IS NOT NULL EXEC(N'ALTER TABLE [CompanyPreferences] DROP CONSTRAINT [' + @var59 + '];');
    ALTER TABLE [CompanyPreferences] DROP COLUMN [EnableSandblastingStep];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308212530_RemoveSandblastingMaskingStepFlags'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T21:25:27.5883784Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308212530_RemoveSandblastingMaskingStepFlags'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T21:25:27.5883789Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308212530_RemoveSandblastingMaskingStepFlags'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-08T21:25:27.5883791Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260308212530_RemoveSandblastingMaskingStepFlags'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260308212530_RemoveSandblastingMaskingStepFlags', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    ALTER TABLE [QuoteStatusLookups] ADD [IsRejectedStatus] bit NOT NULL DEFAULT CAST(0 AS bit);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ApprovalToken] nvarchar(450) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ApprovalTokenExpiresAt] datetime2 NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    ALTER TABLE [Quotes] ADD [ApprovalTokenUsedAt] datetime2 NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    ALTER TABLE [Quotes] ADD [DeclineReason] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    ALTER TABLE [Quotes] ADD [DeclinedByIp] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T12:51:06.7673381Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T12:51:06.7673388Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T12:51:06.7673389Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_Quotes_ApprovalToken] ON [Quotes] ([ApprovalToken]) WHERE [ApprovalToken] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309125110_AddQuoteApprovalToken'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260309125110_AddQuoteApprovalToken', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309134846_MakeChangeHistoryUserIdNullable'
)
BEGIN
    DECLARE @var60 sysname;
    SELECT @var60 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[QuoteChangeHistories]') AND [c].[name] = N'ChangedByUserId');
    IF @var60 IS NOT NULL EXEC(N'ALTER TABLE [QuoteChangeHistories] DROP CONSTRAINT [' + @var60 + '];');
    ALTER TABLE [QuoteChangeHistories] ALTER COLUMN [ChangedByUserId] nvarchar(450) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309134846_MakeChangeHistoryUserIdNullable'
)
BEGIN
    DECLARE @var61 sysname;
    SELECT @var61 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[JobChangeHistories]') AND [c].[name] = N'ChangedByUserId');
    IF @var61 IS NOT NULL EXEC(N'ALTER TABLE [JobChangeHistories] DROP CONSTRAINT [' + @var61 + '];');
    ALTER TABLE [JobChangeHistories] ALTER COLUMN [ChangedByUserId] nvarchar(450) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309134846_MakeChangeHistoryUserIdNullable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T13:48:42.5384960Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309134846_MakeChangeHistoryUserIdNullable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T13:48:42.5384969Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309134846_MakeChangeHistoryUserIdNullable'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T13:48:42.5384970Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309134846_MakeChangeHistoryUserIdNullable'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260309134846_MakeChangeHistoryUserIdNullable', N'8.0.11');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    ALTER TABLE [QuoteItems] ADD [Complexity] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    ALTER TABLE [JobItems] ADD [Complexity] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [ComplexityComplexPercent] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [ComplexityExtremePercent] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [ComplexityModeratePercent] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    ALTER TABLE [CompanyOperatingCosts] ADD [ComplexitySimplePercent] decimal(18,2) NOT NULL DEFAULT 0.0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T19:44:57.1143134Z''
    WHERE [Id] = 1;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T19:44:57.1143138Z''
    WHERE [Id] = 2;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    EXEC(N'UPDATE [PricingTiers] SET [CreatedAt] = ''2026-03-09T19:44:57.1143140Z''
    WHERE [Id] = 3;
    SELECT @@ROWCOUNT');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260309194500_AddComplexityFields'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260309194500_AddComplexityFields', N'8.0.11');
END;
GO

COMMIT;
GO

