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 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 09:30:28 -04:00
parent f03a198e79
commit 3899860c1f
@@ -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
/// <inheritdoc />
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",