BudgetApp/BudgetApp.Storage/Migrations/20260301000000_AddUpdateStatusSingleton.cs
Martin Svrcina e14e552388 Initial commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 01:52:43 +01:00

49 lines
2.0 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BudgetApp.Storage.Migrations
{
/// <inheritdoc />
public partial class AddUpdateStatusSingleton : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "UpdateStatus",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false),
State = table.Column<int>(type: "int", nullable: false),
Created = table.Column<DateTime>(type: "datetime(6)", nullable: false),
Updated = table.Column<DateTime>(type: "datetime(6)", nullable: false),
Deleted = table.Column<DateTime>(type: "datetime(6)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_UpdateStatus", x => x.Id);
table.CheckConstraint("CK_UpdateStatus_SingletonId", "`Id` = 1");
});
migrationBuilder.InsertData(
table: "UpdateStatus",
columns: new[] { "Id", "Created", "Deleted", "State", "Updated" },
values: new object[] { 1, new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc), null, 1, new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc) });
migrationBuilder.Sql(
"CREATE TRIGGER `TR_UpdateStatus_PreventDelete` BEFORE DELETE ON `UpdateStatus` FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'UpdateStatus row cannot be deleted';");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("DROP TRIGGER IF EXISTS `TR_UpdateStatus_PreventDelete`;");
migrationBuilder.DropTable(
name: "UpdateStatus");
}
}
}