﻿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

