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:
+12
-13
@@ -25,15 +25,17 @@ namespace PowderCoating.Infrastructure.Migrations
|
|||||||
nullable: false,
|
nullable: false,
|
||||||
defaultValue: false);
|
defaultValue: false);
|
||||||
|
|
||||||
migrationBuilder.InsertData(
|
// Use raw SQL so we don't collide with an existing row — ID 9 may already be
|
||||||
table: "PlatformSettings",
|
// taken in environments where settings were added outside of migrations.
|
||||||
columns: ["Id", "Key", "Value", "Label", "Description", "GroupName"],
|
migrationBuilder.Sql("""
|
||||||
values: new object[,]
|
IF NOT EXISTS (SELECT 1 FROM [PlatformSettings] WHERE [Key] = N'AiCatalogPriceCheckEnabled')
|
||||||
{
|
BEGIN
|
||||||
{ 9, "AiCatalogPriceCheckEnabled", "true", "AI Catalog Price Check Enabled",
|
INSERT INTO [PlatformSettings] ([Key], [Value], [Label], [Description], [GroupName])
|
||||||
"When true (default), the AI Catalog Price Check feature is available to companies on qualifying plans. Set to false to disable it platform-wide.",
|
VALUES (N'AiCatalogPriceCheckEnabled', N'true', N'AI Catalog Price Check Enabled',
|
||||||
"AI Features" }
|
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(
|
migrationBuilder.UpdateData(
|
||||||
table: "PricingTiers",
|
table: "PricingTiers",
|
||||||
@@ -60,10 +62,7 @@ namespace PowderCoating.Infrastructure.Migrations
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.DeleteData(
|
migrationBuilder.Sql("DELETE FROM [PlatformSettings] WHERE [Key] = N'AiCatalogPriceCheckEnabled'");
|
||||||
table: "PlatformSettings",
|
|
||||||
keyColumn: "Id",
|
|
||||||
keyValue: 9);
|
|
||||||
|
|
||||||
migrationBuilder.DropColumn(
|
migrationBuilder.DropColumn(
|
||||||
name: "AllowAiCatalogPriceCheck",
|
name: "AllowAiCatalogPriceCheck",
|
||||||
|
|||||||
Reference in New Issue
Block a user