From 3899860c1f675568beb50ffbd93290329997d1d4 Mon Sep 17 00:00:00 2001 From: Scott Pouliot Date: Sun, 26 Apr 2026 09:30:28 -0400 Subject: [PATCH] Fix PlatformSettings insert collision in AddAiCatalogPriceCheckGating migration Replace InsertData (hardcoded ID 9) with raw IF NOT EXISTS SQL so the migration is safe on environments where ID 9 is already taken. Co-Authored-By: Claude Sonnet 4.6 --- ...0426122625_AddAiCatalogPriceCheckGating.cs | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/PowderCoating.Infrastructure/Migrations/20260426122625_AddAiCatalogPriceCheckGating.cs b/src/PowderCoating.Infrastructure/Migrations/20260426122625_AddAiCatalogPriceCheckGating.cs index 741473c..c7ec2d3 100644 --- a/src/PowderCoating.Infrastructure/Migrations/20260426122625_AddAiCatalogPriceCheckGating.cs +++ b/src/PowderCoating.Infrastructure/Migrations/20260426122625_AddAiCatalogPriceCheckGating.cs @@ -25,15 +25,17 @@ namespace PowderCoating.Infrastructure.Migrations nullable: false, defaultValue: false); - migrationBuilder.InsertData( - table: "PlatformSettings", - columns: ["Id", "Key", "Value", "Label", "Description", "GroupName"], - values: new object[,] - { - { 9, "AiCatalogPriceCheckEnabled", "true", "AI Catalog Price Check Enabled", - "When true (default), the AI Catalog Price Check feature is available to companies on qualifying plans. Set to false to disable it platform-wide.", - "AI Features" } - }); + // Use raw SQL so we don't collide with an existing row — ID 9 may already be + // taken in environments where settings were added outside of migrations. + migrationBuilder.Sql(""" + IF NOT EXISTS (SELECT 1 FROM [PlatformSettings] WHERE [Key] = N'AiCatalogPriceCheckEnabled') + BEGIN + INSERT INTO [PlatformSettings] ([Key], [Value], [Label], [Description], [GroupName]) + VALUES (N'AiCatalogPriceCheckEnabled', N'true', N'AI Catalog Price Check Enabled', + N'When true (default), the AI Catalog Price Check feature is available to companies on qualifying plans. Set to false to disable it platform-wide.', + N'AI Features'); + END + """); migrationBuilder.UpdateData( table: "PricingTiers", @@ -60,10 +62,7 @@ namespace PowderCoating.Infrastructure.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DeleteData( - table: "PlatformSettings", - keyColumn: "Id", - keyValue: 9); + migrationBuilder.Sql("DELETE FROM [PlatformSettings] WHERE [Key] = N'AiCatalogPriceCheckEnabled'"); migrationBuilder.DropColumn( name: "AllowAiCatalogPriceCheck",