Files
Watcher/watcher-monitoring/Migrations/20260109081821_AddUserApiKeyRelationship.cs
triggermeelmo d8b164e3eb
All checks were successful
Gitea CI/CD / dotnet-build-and-test (push) Successful in 10m5s
Gitea CI/CD / Set Tag Name (push) Successful in 5s
Gitea CI/CD / docker-build-and-push (push) Successful in 11m28s
Gitea CI/CD / Create Tag (push) Successful in 5s
Added Authentication with user-auth and apikey-auth
2026-01-09 10:18:06 +01:00

77 lines
2.2 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace watcher_monitoring.Migrations
{
/// <inheritdoc />
public partial class AddUserApiKeyRelationship : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// Vorhandene API-Keys löschen, da sie keinem User zugeordnet werden können
migrationBuilder.Sql("DELETE FROM ApiKeys;");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
table: "Users",
type: "TEXT",
nullable: false,
defaultValue: DateTime.UtcNow);
migrationBuilder.AddColumn<bool>(
name: "IsActive",
table: "Users",
type: "INTEGER",
nullable: false,
defaultValue: true);
migrationBuilder.AddColumn<int>(
name: "UserId",
table: "ApiKeys",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateIndex(
name: "IX_ApiKeys_UserId",
table: "ApiKeys",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_ApiKeys_Users_UserId",
table: "ApiKeys",
column: "UserId",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ApiKeys_Users_UserId",
table: "ApiKeys");
migrationBuilder.DropIndex(
name: "IX_ApiKeys_UserId",
table: "ApiKeys");
migrationBuilder.DropColumn(
name: "CreatedAt",
table: "Users");
migrationBuilder.DropColumn(
name: "IsActive",
table: "Users");
migrationBuilder.DropColumn(
name: "UserId",
table: "ApiKeys");
}
}
}