// <auto-generated />
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AliasServerDb.Migrations
{
    /// <inheritdoc />
    public partial class PreserveEmailClaimsForDeletedUsers : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
                table: "Emails");

            migrationBuilder.DropForeignKey(
                name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
                table: "UserEmailClaims");

            migrationBuilder.AlterColumn<string>(
                name: "UserId",
                table: "UserEmailClaims",
                type: "TEXT",
                maxLength: 255,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldMaxLength: 255);

            migrationBuilder.AddForeignKey(
                name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
                table: "Emails",
                column: "UserEncryptionKeyId",
                principalTable: "UserEncryptionKeys",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
                table: "UserEmailClaims",
                column: "UserId",
                principalTable: "AliasVaultUsers",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
                table: "Emails");

            migrationBuilder.DropForeignKey(
                name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
                table: "UserEmailClaims");

            migrationBuilder.AlterColumn<string>(
                name: "UserId",
                table: "UserEmailClaims",
                type: "TEXT",
                maxLength: 255,
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldMaxLength: 255,
                oldNullable: true);

            migrationBuilder.AddForeignKey(
                name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
                table: "Emails",
                column: "UserEncryptionKeyId",
                principalTable: "UserEncryptionKeys",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
                table: "UserEmailClaims",
                column: "UserId",
                principalTable: "AliasVaultUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
