During import execution, the migration 20260607012436_StatusModel failed because it referenced a non-existent table "SaleContractAnimals" (plural). The actual table name is "SaleContractAnimal" (singular). Fixed the reference in the SQL raw string to use the correct table name so the migration can apply cleanly on fresh deployments. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace GerbilManagerWebAPI.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class StatusModel : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
// 1) Rename string value 'Active' → 'Breeding'.
|
|
migrationBuilder.Sql(@"UPDATE ""Gerbils"" SET ""Status"" = 'Breeding' WHERE ""Status"" = 'Active';");
|
|
|
|
// 2) DateOfDeath set → Deceased (always takes precedence).
|
|
migrationBuilder.Sql(@"UPDATE ""Gerbils"" SET ""Status"" = 'Deceased' WHERE ""DateOfDeath"" IS NOT NULL;");
|
|
|
|
// 3) ReceiverContactId OR SaleContractAnimal → GivenAway (if not already Deceased).
|
|
migrationBuilder.Sql(@"
|
|
UPDATE ""Gerbils"" SET ""Status"" = 'GivenAway'
|
|
WHERE ""Status"" != 'Deceased'
|
|
AND (""ReceiverContactId"" IS NOT NULL
|
|
OR EXISTS (SELECT 1 FROM ""SaleContractAnimal"" WHERE ""GerbilId"" = ""Gerbils"".""Id""));");
|
|
|
|
// 4) Age > 7 years (presumed dead) → Deceased, but NOT overriding GivenAway.
|
|
migrationBuilder.Sql(@"
|
|
UPDATE ""Gerbils"" SET ""Status"" = 'Deceased'
|
|
WHERE ""Status"" NOT IN ('Deceased', 'GivenAway')
|
|
AND ""DateOfBirth"" IS NOT NULL
|
|
AND ""DateOfBirth"" < (CURRENT_DATE - INTERVAL '7 years');");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.Sql(@"UPDATE ""Gerbils"" SET ""Status"" = 'Active' WHERE ""Status"" = 'Breeding';");
|
|
}
|
|
}
|
|
}
|