36 lines
1.1 KiB
C#
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");
|
|
}
|
|
}
|
|
}
|