using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace watcher_monitoring.Migrations { /// public partial class AddUserApiKeyRelationship : Migration { /// 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( name: "CreatedAt", table: "Users", type: "TEXT", nullable: false, defaultValue: DateTime.UtcNow); migrationBuilder.AddColumn( name: "IsActive", table: "Users", type: "INTEGER", nullable: false, defaultValue: true); migrationBuilder.AddColumn( 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); } /// 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"); } } }