﻿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

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])
);
GO

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])
);
GO

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])
);
GO

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])
);
GO

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])
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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
);
GO

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;
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;
GO

CREATE INDEX [IX_AspNetRoleClaims_RoleId] ON [AspNetRoleClaims] ([RoleId]);
GO

CREATE UNIQUE INDEX [RoleNameIndex] ON [AspNetRoles] ([NormalizedName]) WHERE [NormalizedName] IS NOT NULL;
GO

CREATE INDEX [IX_AspNetUserClaims_UserId] ON [AspNetUserClaims] ([UserId]);
GO

CREATE INDEX [IX_AspNetUserLogins_UserId] ON [AspNetUserLogins] ([UserId]);
GO

CREATE INDEX [IX_AspNetUserRoles_RoleId] ON [AspNetUserRoles] ([RoleId]);
GO

CREATE INDEX [EmailIndex] ON [AspNetUsers] ([NormalizedEmail]);
GO

CREATE UNIQUE INDEX [UserNameIndex] ON [AspNetUsers] ([NormalizedUserName]) WHERE [NormalizedUserName] IS NOT NULL;
GO

CREATE INDEX [IX_CustomerNotes_CustomerId] ON [CustomerNotes] ([CustomerId]);
GO

CREATE INDEX [IX_Customers_CompanyName] ON [Customers] ([CompanyName]);
GO

CREATE UNIQUE INDEX [IX_Customers_Email] ON [Customers] ([Email]);
GO

CREATE INDEX [IX_Customers_PricingTierId] ON [Customers] ([PricingTierId]);
GO

CREATE INDEX [IX_InventoryItems_PrimarySupplierId] ON [InventoryItems] ([PrimarySupplierId]);
GO

CREATE UNIQUE INDEX [IX_InventoryItems_SKU] ON [InventoryItems] ([SKU]);
GO

CREATE INDEX [IX_InventoryTransactions_InventoryItemId] ON [InventoryTransactions] ([InventoryItemId]);
GO

CREATE INDEX [IX_JobItems_JobId] ON [JobItems] ([JobId]);
GO

CREATE INDEX [IX_JobItems_PowderInventoryId] ON [JobItems] ([PowderInventoryId]);
GO

CREATE INDEX [IX_JobNotes_JobId] ON [JobNotes] ([JobId]);
GO

CREATE INDEX [IX_JobPhotos_JobId] ON [JobPhotos] ([JobId]);
GO

CREATE INDEX [IX_Jobs_AssignedEmployeeId] ON [Jobs] ([AssignedEmployeeId]);
GO

CREATE INDEX [IX_Jobs_CustomerId] ON [Jobs] ([CustomerId]);
GO

CREATE UNIQUE INDEX [IX_Jobs_JobNumber] ON [Jobs] ([JobNumber]);
GO

CREATE UNIQUE INDEX [IX_Jobs_QuoteId] ON [Jobs] ([QuoteId]) WHERE [QuoteId] IS NOT NULL;
GO

CREATE INDEX [IX_JobStatusHistory_JobId] ON [JobStatusHistory] ([JobId]);
GO

CREATE INDEX [IX_MaintenanceRecords_EquipmentId] ON [MaintenanceRecords] ([EquipmentId]);
GO

CREATE INDEX [IX_MaintenanceRecords_PerformedById] ON [MaintenanceRecords] ([PerformedById]);
GO

CREATE INDEX [IX_QuoteItems_QuoteId] ON [QuoteItems] ([QuoteId]);
GO

CREATE INDEX [IX_Quotes_CustomerId] ON [Quotes] ([CustomerId]);
GO

CREATE INDEX [IX_Quotes_PreparedById] ON [Quotes] ([PreparedById]);
GO

CREATE UNIQUE INDEX [IX_Quotes_QuoteNumber] ON [Quotes] ([QuoteNumber]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260205163837_InitialCreate', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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])
);
GO

CREATE UNIQUE INDEX [IX_Companies_CompanyCode] ON [Companies] ([CompanyCode]) WHERE [CompanyCode] IS NOT NULL;
GO


                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;
            
GO

ALTER TABLE [Suppliers] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [Quotes] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [QuoteItems] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [PricingTiers] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [MaintenanceRecords] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [JobStatusHistory] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [Jobs] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [JobPhotos] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [JobNotes] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [JobItems] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [InventoryTransactions] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [InventoryItems] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [Equipment] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [Customers] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [CustomerNotes] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [AspNetUsers] ADD [CompanyId] int NOT NULL DEFAULT 1;
GO

ALTER TABLE [AspNetUsers] ADD [CompanyRole] nvarchar(max) NULL;
GO

UPDATE [PricingTiers] SET [CompanyId] = 1, [CreatedAt] = '2026-02-06T01:20:42.5015235Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CompanyId] = 1, [CreatedAt] = '2026-02-06T01:20:42.5015242Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CompanyId] = 1, [CreatedAt] = '2026-02-06T01:20:42.5015243Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_Suppliers_CompanyId] ON [Suppliers] ([CompanyId]);
GO

CREATE INDEX [IX_Quotes_CompanyId] ON [Quotes] ([CompanyId]);
GO

CREATE INDEX [IX_PricingTiers_CompanyId] ON [PricingTiers] ([CompanyId]);
GO

CREATE INDEX [IX_Jobs_CompanyId] ON [Jobs] ([CompanyId]);
GO

CREATE INDEX [IX_InventoryItems_CompanyId] ON [InventoryItems] ([CompanyId]);
GO

CREATE INDEX [IX_Equipment_CompanyId] ON [Equipment] ([CompanyId]);
GO

CREATE INDEX [IX_Customers_CompanyId] ON [Customers] ([CompanyId]);
GO

CREATE INDEX [IX_AspNetUsers_CompanyId] ON [AspNetUsers] ([CompanyId]);
GO

ALTER TABLE [AspNetUsers] ADD CONSTRAINT [FK_AspNetUsers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [Customers] ADD CONSTRAINT [FK_Customers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [Equipment] ADD CONSTRAINT [FK_Equipment_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [InventoryItems] ADD CONSTRAINT [FK_InventoryItems_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [PricingTiers] ADD CONSTRAINT [FK_PricingTiers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [Quotes] ADD CONSTRAINT [FK_Quotes_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [Suppliers] ADD CONSTRAINT [FK_Suppliers_Companies_CompanyId] FOREIGN KEY ([CompanyId]) REFERENCES [Companies] ([Id]) ON DELETE NO ACTION;
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260206012125_AddMultiTenancy', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T15:00:38.8151700Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T15:00:38.8151704Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T15:00:38.8151706Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260206150138_MakeCompanyNameOptional', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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
);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T17:43:30.0415021Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T17:43:30.0415026Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T17:43:30.0415028Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE UNIQUE INDEX [IX_CompanyOperatingCosts_CompanyId] ON [CompanyOperatingCosts] ([CompanyId]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260206174417_AddCompanyOperatingCosts', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

DROP INDEX [IX_Customers_Email] ON [Customers];
GO

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;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T21:35:23.2581715Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T21:35:23.2581722Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-06T21:35:23.2581724Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE UNIQUE INDEX [IX_Customers_Email] ON [Customers] ([Email]) WHERE [Email] IS NOT NULL;
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260206213627_MakeCustomerEmailOptional', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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;
GO

ALTER TABLE [Quotes] ADD [ProspectAddress] nvarchar(max) NULL;
GO

ALTER TABLE [Quotes] ADD [ProspectCity] nvarchar(max) NULL;
GO

ALTER TABLE [Quotes] ADD [ProspectCompanyName] nvarchar(max) NULL;
GO

ALTER TABLE [Quotes] ADD [ProspectContactName] nvarchar(max) NULL;
GO

ALTER TABLE [Quotes] ADD [ProspectEmail] nvarchar(max) NULL;
GO

ALTER TABLE [Quotes] ADD [ProspectPhone] nvarchar(max) NULL;
GO

ALTER TABLE [Quotes] ADD [ProspectState] nvarchar(max) NULL;
GO

ALTER TABLE [Quotes] ADD [ProspectZipCode] nvarchar(max) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T03:42:43.2794915Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T03:42:43.2794919Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T03:42:43.2794921Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260207034246_UpdateQuoteForProspects', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [CompanyOperatingCosts] ADD [PowderCoatingCostPerSqFt] decimal(18,2) NOT NULL DEFAULT 0.0;
GO

ALTER TABLE [CompanyOperatingCosts] ADD [TaxPercent] decimal(18,2) NOT NULL DEFAULT 0.0;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T03:55:32.3427640Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T03:55:32.3427647Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T03:55:32.3427649Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260207035534_AddPowderCoatingCostAndTaxToOperatingCosts', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [QuoteItems] ADD [InventoryItemId] int NULL;
GO

ALTER TABLE [QuoteItems] ADD [PowderCostOverride] decimal(18,2) NULL;
GO

ALTER TABLE [QuoteItems] ADD [SurfaceAreaSqFt] decimal(18,2) NOT NULL DEFAULT 0.0;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T04:32:10.0998342Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T04:32:10.0998349Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T04:32:10.0998351Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_QuoteItems_InventoryItemId] ON [QuoteItems] ([InventoryItemId]);
GO

ALTER TABLE [QuoteItems] ADD CONSTRAINT [FK_QuoteItems_InventoryItems_InventoryItemId] FOREIGN KEY ([InventoryItemId]) REFERENCES [InventoryItems] ([Id]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260207043212_AddPowderCostFieldsToQuoteItems', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [InventoryItems] ADD [CoverageSqFtPerLb] decimal(18,2) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T15:28:54.4593675Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T15:28:54.4593680Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T15:28:54.4593682Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260207152856_AddCoverageSqFtPerLbToInventoryItem', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [InventoryItems] ADD [TransferEfficiency] decimal(18,2) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T15:35:42.9455847Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T15:35:42.9455851Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T15:35:42.9455853Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260207153545_AddTransferEfficiencyToInventoryItem', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [MaintenanceRecords] ADD [AssignedWorkerId] int NULL;
GO

ALTER TABLE [Jobs] ADD [AssignedWorkerId] int NULL;
GO

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
);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T20:06:23.0605718Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T20:06:23.0605725Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-07T20:06:23.0605728Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_MaintenanceRecords_AssignedWorkerId] ON [MaintenanceRecords] ([AssignedWorkerId]);
GO

CREATE INDEX [IX_Jobs_AssignedWorkerId] ON [Jobs] ([AssignedWorkerId]);
GO

CREATE INDEX [IX_ShopWorkers_CompanyId] ON [ShopWorkers] ([CompanyId]);
GO

ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_ShopWorkers_AssignedWorkerId] FOREIGN KEY ([AssignedWorkerId]) REFERENCES [ShopWorkers] ([Id]) ON DELETE SET NULL;
GO

ALTER TABLE [MaintenanceRecords] ADD CONSTRAINT [FK_MaintenanceRecords_ShopWorkers_AssignedWorkerId] FOREIGN KEY ([AssignedWorkerId]) REFERENCES [ShopWorkers] ([Id]) ON DELETE SET NULL;
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260207200633_AddShopWorkers', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

EXEC sp_rename N'[Companies].[LogoPath]', N'LogoContentType', N'COLUMN';
GO

ALTER TABLE [Companies] ADD [LogoData] varbinary(max) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T16:00:14.7529664Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T16:00:14.7529711Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T16:00:14.7529713Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260208160017_StoreLogoInDatabase', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

EXEC sp_rename N'[AspNetUsers].[ProfilePicturePath]', N'SidebarColor', N'COLUMN';
GO

ALTER TABLE [AspNetUsers] ADD [ProfilePictureContentType] nvarchar(max) NULL;
GO

ALTER TABLE [AspNetUsers] ADD [ProfilePictureData] varbinary(max) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T16:43:39.0977992Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T16:43:39.0978000Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T16:43:39.0978002Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260208164341_AddProfilePictureAndSidebarColor', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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
);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T18:14:35.8493756Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T18:14:35.8493760Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T18:14:35.8493762Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE UNIQUE INDEX [IX_CompanyPreferences_CompanyId] ON [CompanyPreferences] ([CompanyId]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260208181438_AddCompanyPreferences', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [Customers] ADD [IsTaxExempt] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

ALTER TABLE [Customers] ADD [TaxExemptCertificateContentType] nvarchar(max) NULL;
GO

ALTER TABLE [Customers] ADD [TaxExemptCertificateData] varbinary(max) NULL;
GO

ALTER TABLE [Customers] ADD [TaxExemptCertificateFileName] nvarchar(max) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T22:44:23.0992986Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T22:44:23.0992993Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T22:44:23.0992995Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260208224426_AddTaxExemptionToCustomer', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [CompanyOperatingCosts] ADD [RushChargePercentage] decimal(18,2) NOT NULL DEFAULT 0.0;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T23:03:20.9733994Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T23:03:20.9733999Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T23:03:20.9734001Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260208230323_AddRushChargePercentage', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [CompanyOperatingCosts] ADD [ShopMinimumCharge] decimal(18,2) NOT NULL DEFAULT 0.0;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T23:14:05.6375506Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T23:14:05.6375510Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-08T23:14:05.6375512Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260208231408_AddShopMinimumCharge', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [AspNetUsers] ADD [ProfilePictureFilePath] nvarchar(max) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T00:28:19.8975461Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T00:28:19.8975466Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T00:28:19.8975469Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260211002823_AddProfilePictureFilePath', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

EXEC sp_rename N'[JobPhotos].[PhotoDate]', N'UploadedDate', N'COLUMN';
GO

EXEC sp_rename N'[JobPhotos].[Description]', N'Caption', N'COLUMN';
GO

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;
GO

ALTER TABLE [JobPhotos] ADD [ContentType] nvarchar(max) NOT NULL DEFAULT N'';
GO

ALTER TABLE [JobPhotos] ADD [DisplayOrder] int NOT NULL DEFAULT 0;
GO

ALTER TABLE [JobPhotos] ADD [FileSize] bigint NOT NULL DEFAULT CAST(0 AS bigint);
GO

ALTER TABLE [JobPhotos] ADD [UploadedById] nvarchar(450) NOT NULL DEFAULT N'';
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T00:54:54.2629259Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T00:54:54.2629263Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T00:54:54.2629265Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_JobPhotos_UploadedById] ON [JobPhotos] ([UploadedById]);
GO

ALTER TABLE [JobPhotos] ADD CONSTRAINT [FK_JobPhotos_AspNetUsers_UploadedById] FOREIGN KEY ([UploadedById]) REFERENCES [AspNetUsers] ([Id]) ON DELETE CASCADE;
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260211005456_UpdateJobPhotoEntity', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [Equipment] ADD [ManualContentType] nvarchar(max) NULL;
GO

ALTER TABLE [Equipment] ADD [ManualFileName] nvarchar(max) NULL;
GO

ALTER TABLE [Equipment] ADD [ManualFilePath] nvarchar(max) NULL;
GO

ALTER TABLE [Equipment] ADD [ManualFileSize] bigint NULL;
GO

ALTER TABLE [Equipment] ADD [ManualUploadedDate] datetime2 NULL;
GO

ALTER TABLE [Companies] ADD [LogoFilePath] nvarchar(max) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T02:06:13.9839041Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T02:06:13.9839046Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T02:06:13.9839048Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260211020617_AddFileSystemStorageForLogosAndManuals', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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
);
GO

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
);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T02:47:52.8155540Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T02:47:52.8155546Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T02:47:52.8155548Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_CatalogCategories_CompanyId] ON [CatalogCategories] ([CompanyId]);
GO

CREATE INDEX [IX_CatalogCategories_ParentCategoryId] ON [CatalogCategories] ([ParentCategoryId]);
GO

CREATE INDEX [IX_CatalogItems_CategoryId] ON [CatalogItems] ([CategoryId]);
GO

CREATE INDEX [IX_CatalogItems_CompanyId] ON [CatalogItems] ([CompanyId]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260211024755_AddProductCatalog', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [QuoteItems] ADD [CatalogItemId] int NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T04:38:17.1662142Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T04:38:17.1662149Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T04:38:17.1662151Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_QuoteItems_CatalogItemId] ON [QuoteItems] ([CatalogItemId]);
GO

ALTER TABLE [QuoteItems] ADD CONSTRAINT [FK_QuoteItems_CatalogItems_CatalogItemId] FOREIGN KEY ([CatalogItemId]) REFERENCES [CatalogItems] ([Id]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260211043819_AddCatalogItemIdToQuoteItems', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

EXEC sp_rename N'[CompanyOperatingCosts].[WaterRatePerUnit]', N'RushChargeFixedAmount', N'COLUMN';
GO

ALTER TABLE [CompanyOperatingCosts] ADD [RushChargeType] nvarchar(20) NOT NULL DEFAULT N'Percentage';
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T19:55:20.0897507Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T19:55:20.0897511Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-11T19:55:20.0897513Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260211195523_UpdateOperatingCostsRushCharge', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [Jobs] DROP CONSTRAINT [FK_Jobs_AspNetUsers_AssignedEmployeeId];
GO

DROP INDEX [IX_Jobs_AssignedEmployeeId] ON [Jobs];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T13:50:54.4827815Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T13:50:54.4827821Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T13:50:54.4827822Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260213135057_RemoveUnusedFields', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [Suppliers] ADD [AccountNumber] nvarchar(max) NULL;
GO

ALTER TABLE [Suppliers] ADD [CreditLimit] decimal(18,2) NULL;
GO

ALTER TABLE [Suppliers] ADD [IsPreferred] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

ALTER TABLE [Suppliers] ADD [PaymentTerms] nvarchar(max) NULL;
GO

ALTER TABLE [Suppliers] ADD [TaxId] nvarchar(max) NULL;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T16:25:10.0855660Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T16:25:10.0855668Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T16:25:10.0855669Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260213162512_AddSupplierEnhancements', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [Jobs] ADD [OldStatus] int NOT NULL DEFAULT 0;
GO

ALTER TABLE [Jobs] ADD [OldPriority] int NOT NULL DEFAULT 0;
GO

ALTER TABLE [Quotes] ADD [OldStatus] int NOT NULL DEFAULT 0;
GO

ALTER TABLE [JobStatusHistory] ADD [OldFromStatus] int NOT NULL DEFAULT 0;
GO

ALTER TABLE [JobStatusHistory] ADD [OldToStatus] int NOT NULL DEFAULT 0;
GO

UPDATE Jobs SET OldStatus = Status, OldPriority = Priority
GO

UPDATE Quotes SET OldStatus = Status
GO

UPDATE JobStatusHistory SET OldFromStatus = FromStatus, OldToStatus = ToStatus
GO

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
);
GO

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
);
GO

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
);
GO


                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
            
GO


                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
            
GO


                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
            
GO

EXEC sp_rename N'[Jobs].[Status]', N'JobStatusId_OLD', N'COLUMN';
GO

EXEC sp_rename N'[Jobs].[Priority]', N'JobPriorityId_OLD', N'COLUMN';
GO

EXEC sp_rename N'[Quotes].[Status]', N'QuoteStatusId_OLD', N'COLUMN';
GO

EXEC sp_rename N'[JobStatusHistory].[FromStatus]', N'FromStatusId_OLD', N'COLUMN';
GO

EXEC sp_rename N'[JobStatusHistory].[ToStatus]', N'ToStatusId_OLD', N'COLUMN';
GO

ALTER TABLE [Jobs] ADD [JobStatusId] int NULL;
GO

ALTER TABLE [Jobs] ADD [JobPriorityId] int NULL;
GO

ALTER TABLE [Quotes] ADD [QuoteStatusId] int NULL;
GO

ALTER TABLE [JobStatusHistory] ADD [FromStatusId] int NULL;
GO

ALTER TABLE [JobStatusHistory] ADD [ToStatusId] int NULL;
GO


                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
            
GO


                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
            
GO


                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
            
GO


                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
            
GO


                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
            
GO

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;
GO

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;
GO

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;
GO

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;
GO

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;
GO

CREATE INDEX [IX_Jobs_JobStatusId] ON [Jobs] ([JobStatusId]);
GO

CREATE INDEX [IX_Jobs_JobPriorityId] ON [Jobs] ([JobPriorityId]);
GO

CREATE INDEX [IX_Quotes_QuoteStatusId] ON [Quotes] ([QuoteStatusId]);
GO

CREATE INDEX [IX_JobStatusHistory_FromStatusId] ON [JobStatusHistory] ([FromStatusId]);
GO

CREATE INDEX [IX_JobStatusHistory_ToStatusId] ON [JobStatusHistory] ([ToStatusId]);
GO

CREATE INDEX [IX_JobStatusLookups_CompanyId] ON [JobStatusLookups] ([CompanyId]);
GO

CREATE UNIQUE INDEX [IX_JobStatusLookups_CompanyId_StatusCode] ON [JobStatusLookups] ([CompanyId], [StatusCode]);
GO

CREATE INDEX [IX_JobPriorityLookups_CompanyId] ON [JobPriorityLookups] ([CompanyId]);
GO

CREATE UNIQUE INDEX [IX_JobPriorityLookups_CompanyId_PriorityCode] ON [JobPriorityLookups] ([CompanyId], [PriorityCode]);
GO

CREATE INDEX [IX_QuoteStatusLookups_CompanyId] ON [QuoteStatusLookups] ([CompanyId]);
GO

CREATE UNIQUE INDEX [IX_QuoteStatusLookups_CompanyId_StatusCode] ON [QuoteStatusLookups] ([CompanyId], [StatusCode]);
GO

ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_JobStatusLookups_JobStatusId] FOREIGN KEY ([JobStatusId]) REFERENCES [JobStatusLookups] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [Jobs] ADD CONSTRAINT [FK_Jobs_JobPriorityLookups_JobPriorityId] FOREIGN KEY ([JobPriorityId]) REFERENCES [JobPriorityLookups] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [Quotes] ADD CONSTRAINT [FK_Quotes_QuoteStatusLookups_QuoteStatusId] FOREIGN KEY ([QuoteStatusId]) REFERENCES [QuoteStatusLookups] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [JobStatusHistory] ADD CONSTRAINT [FK_JobStatusHistory_JobStatusLookups_FromStatusId] FOREIGN KEY ([FromStatusId]) REFERENCES [JobStatusLookups] ([Id]) ON DELETE NO ACTION;
GO

ALTER TABLE [JobStatusHistory] ADD CONSTRAINT [FK_JobStatusHistory_JobStatusLookups_ToStatusId] FOREIGN KEY ([ToStatusId]) REFERENCES [JobStatusLookups] ([Id]) ON DELETE NO ACTION;
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

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];
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T18:39:09.9091116Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T18:39:09.9091124Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-13T18:39:09.9091127Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260213183913_ConvertEnumsToLookupTables', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [CompanyOperatingCosts] ADD [ShopSuppliesRate] decimal(18,2) NOT NULL DEFAULT 0.0;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T02:38:28.7266427Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T02:38:28.7266433Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T02:38:28.7266437Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260214023832_AddShopSuppliesRateToOperatingCosts', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [InventoryItems] ADD [InventoryCategoryId] int NULL;
GO

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
);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T04:18:25.8821520Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T04:18:25.8821525Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T04:18:25.8821527Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO


                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
            
GO


                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'
            
GO

CREATE INDEX [IX_InventoryItems_InventoryCategoryId] ON [InventoryItems] ([InventoryCategoryId]);
GO

CREATE INDEX [IX_InventoryCategoryLookups_CompanyId] ON [InventoryCategoryLookups] ([CompanyId]);
GO

CREATE UNIQUE INDEX [IX_InventoryCategoryLookups_CompanyId_CategoryCode] ON [InventoryCategoryLookups] ([CompanyId], [CategoryCode]);
GO

ALTER TABLE [InventoryItems] ADD CONSTRAINT [FK_InventoryItems_InventoryCategoryLookups_InventoryCategoryId] FOREIGN KEY ([InventoryCategoryId]) REFERENCES [InventoryCategoryLookups] ([Id]) ON DELETE NO ACTION;
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260214041829_AddInventoryCategoryLookup', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [InventoryCategoryLookups] ADD [IsCoating] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T04:46:02.4897150Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T04:46:02.4897155Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T04:46:02.4897157Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260214044605_AddIsCoatingToInventoryCategory', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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
);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T16:34:11.9752246Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T16:34:11.9752252Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T16:34:11.9752254Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_QuoteChangeHistories_ChangedByUserId] ON [QuoteChangeHistories] ([ChangedByUserId]);
GO

CREATE INDEX [IX_QuoteChangeHistories_CompanyId] ON [QuoteChangeHistories] ([CompanyId]);
GO

CREATE INDEX [IX_QuoteChangeHistories_QuoteId] ON [QuoteChangeHistories] ([QuoteId]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260214163415_AddQuoteChangeHistory', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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
);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T17:09:52.0923949Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T17:09:52.0923957Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T17:09:52.0923959Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_JobChangeHistories_ChangedByUserId] ON [JobChangeHistories] ([ChangedByUserId]);
GO

CREATE INDEX [IX_JobChangeHistories_CompanyId] ON [JobChangeHistories] ([CompanyId]);
GO

CREATE INDEX [IX_JobChangeHistories_JobId] ON [JobChangeHistories] ([JobId]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260214170954_AddJobChangeHistory', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [CompanyPreferences] ADD [UseMetricSystem] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T18:29:01.4505899Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T18:29:01.4505906Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T18:29:01.4505907Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260214182904_AddMetricSystemPreference', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

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])
);
GO

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])
);
GO

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])
);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T22:13:31.2633342Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T22:13:31.2633348Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-14T22:13:31.2633349Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_Appointments_AppointmentStatusId] ON [Appointments] ([AppointmentStatusId]);
GO

CREATE INDEX [IX_Appointments_AppointmentTypeId] ON [Appointments] ([AppointmentTypeId]);
GO

CREATE INDEX [IX_Appointments_AssignedWorkerId] ON [Appointments] ([AssignedWorkerId]);
GO

CREATE INDEX [IX_Appointments_CustomerId] ON [Appointments] ([CustomerId]);
GO

CREATE INDEX [IX_Appointments_JobId] ON [Appointments] ([JobId]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260214221334_AddAppointmentScheduling', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [Appointments] DROP CONSTRAINT [FK_Appointments_Customers_CustomerId];
GO

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;
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T00:05:25.6925144Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T00:05:25.6925153Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T00:05:25.6925155Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

ALTER TABLE [Appointments] ADD CONSTRAINT [FK_Appointments_Customers_CustomerId] FOREIGN KEY ([CustomerId]) REFERENCES [Customers] ([Id]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260215000528_MakeAppointmentCustomerIdOptional', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

ALTER TABLE [AspNetUsers] ADD [CanManageCalendar] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

ALTER TABLE [AspNetUsers] ADD [CanManageEquipment] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

ALTER TABLE [AspNetUsers] ADD [CanManageMaintenance] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

ALTER TABLE [AspNetUsers] ADD [CanManageProducts] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

ALTER TABLE [AspNetUsers] ADD [CanManageSuppliers] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

ALTER TABLE [AspNetUsers] ADD [CanViewCalendar] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

ALTER TABLE [AspNetUsers] ADD [CanViewProducts] bit NOT NULL DEFAULT CAST(0 AS bit);
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T00:34:41.2332987Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T00:34:41.2332995Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T00:34:41.2332997Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260215003444_AddAdditionalUserPermissions', N'8.0.11');
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

DROP INDEX [IX_JobPhotos_JobId] ON [JobPhotos];
GO

DROP INDEX [IX_JobNotes_JobId] ON [JobNotes];
GO

DROP INDEX [IX_CustomerNotes_CustomerId] ON [CustomerNotes];
GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T05:05:35.3159644Z'
WHERE [Id] = 1;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T05:05:35.3159650Z'
WHERE [Id] = 2;
SELECT @@ROWCOUNT;

GO

UPDATE [PricingTiers] SET [CreatedAt] = '2026-02-15T05:05:35.3159652Z'
WHERE [Id] = 3;
SELECT @@ROWCOUNT;

GO

CREATE INDEX [IX_Quotes_CompanyId_ExpirationDate] ON [Quotes] ([CompanyId], [ExpirationDate]);
GO

CREATE INDEX [IX_Quotes_CompanyId_QuoteStatusId] ON [Quotes] ([CompanyId], [QuoteStatusId]);
GO

CREATE INDEX [IX_MaintenanceRecords_CompanyId_ScheduledDate] ON [MaintenanceRecords] ([CompanyId], [ScheduledDate]);
GO

CREATE INDEX [IX_MaintenanceRecords_CompanyId_Status] ON [MaintenanceRecords] ([CompanyId], [Status]);
GO

CREATE INDEX [IX_Jobs_CompanyId_CustomerId] ON [Jobs] ([CompanyId], [CustomerId]);
GO

CREATE INDEX [IX_Jobs_CompanyId_DueDate] ON [Jobs] ([CompanyId], [DueDate]);
GO

CREATE INDEX [IX_Jobs_CompanyId_JobPriorityId] ON [Jobs] ([CompanyId], [JobPriorityId]);
GO

CREATE INDEX [IX_Jobs_CompanyId_JobStatusId] ON [Jobs] ([CompanyId], [JobStatusId]);
GO

CREATE INDEX [IX_Jobs_CompanyId_ScheduledDate] ON [Jobs] ([CompanyId], [ScheduledDate]);
GO

CREATE INDEX [IX_JobPhotos_JobId_IsDeleted_DisplayOrder] ON [JobPhotos] ([JobId], [IsDeleted], [DisplayOrder]);
GO

CREATE INDEX [IX_JobNotes_JobId_CreatedAt] ON [JobNotes] ([JobId], [CreatedAt]);
GO

CREATE INDEX [IX_JobItems_JobId_IsDeleted] ON [JobItems] ([JobId], [IsDeleted]);
GO

CREATE INDEX [IX_InventoryItems_CompanyId_Quantity_Reorder] ON [InventoryItems] ([CompanyId], [QuantityOnHand], [ReorderPoint]);
GO

CREATE INDEX [IX_Equipment_CompanyId_Status] ON [Equipment] ([CompanyId], [Status]);
GO

CREATE INDEX [IX_CustomerNotes_CustomerId_CreatedAt] ON [CustomerNotes] ([CustomerId], [CreatedAt]);
GO

CREATE INDEX [IX_Appointments_CompanyId_AppointmentStatusId] ON [Appointments] ([CompanyId], [AppointmentStatusId]);
GO

CREATE INDEX [IX_Appointments_CompanyId_ScheduledStartTime] ON [Appointments] ([CompanyId], [ScheduledStartTime]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20260215050538_AddPerformanceIndexes', N'8.0.11');
GO

COMMIT;
GO

