Files
watcher/Watcher/Migrations/20251117142850_StartServerIdsAtZero.cs
triggermeelmo f8961320c5
All checks were successful
Gitea CI/CD / dotnet-build-and-test (push) Successful in 55s
Gitea CI/CD / Set Tag Name (push) Successful in 6s
Gitea CI/CD / docker-build-and-push (push) Successful in 7m42s
Gitea CI/CD / Create Tag (push) Successful in 7s
DB startet Server bei ID 0
2025-11-17 15:37:28 +01:00

36 lines
1.1 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Watcher.Migrations
{
/// <inheritdoc />
public partial class StartServerIdsAtZero : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddCheckConstraint(
name: "CK_Server_Id",
table: "Servers",
sql: "Id >= 0");
// Bestehende Server-IDs um 1 verringern (1 -> 0, 2 -> 1, etc.)
migrationBuilder.Sql(@"
UPDATE Servers SET Id = Id - 1;
UPDATE Metrics SET ServerId = ServerId - 1 WHERE ServerId IS NOT NULL;
UPDATE Containers SET ServerId = ServerId - 1 WHERE ServerId IS NOT NULL;
UPDATE sqlite_sequence SET seq = seq - 1 WHERE name = 'Servers';
");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropCheckConstraint(
name: "CK_Server_Id",
table: "Servers");
}
}
}