using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Monitoring.Infrastructure.Data.Migrations;

/// <inheritdoc />
public partial class ExchangeUserToMemberInAccesses : Migration
{
	/// <inheritdoc />
	protected override void Up(MigrationBuilder migrationBuilder)
	{
		_ = migrationBuilder.DropForeignKey(
			name: "FK_Accesses_Users_UserId",
			table: "Accesses");

		_ = migrationBuilder.DropIndex(
			name: "IX_Accesses_AssetId_UserId",
			table: "Accesses");

		_ = migrationBuilder.DropIndex(
			name: "IX_Accesses_UserId",
			table: "Accesses");

		_ = migrationBuilder.RenameColumn(
			name: "UserId",
			table: "Accesses",
			newName: "MemberId");

		_ = migrationBuilder.CreateIndex(
			name: "IX_Accesses_AssetId",
			table: "Accesses",
			column: "AssetId");

		_ = migrationBuilder.CreateIndex(
			name: "IX_Accesses_MemberId_AssetId",
			table: "Accesses",
			columns: new[] { "MemberId", "AssetId" },
			unique: true);

		_ = migrationBuilder.AddForeignKey(
			name: "FK_Accesses_Members_MemberId",
			table: "Accesses",
			column: "MemberId",
			principalTable: "Members",
			principalColumn: "Id",
			onDelete: ReferentialAction.Cascade);
	}

	/// <inheritdoc />
	protected override void Down(MigrationBuilder migrationBuilder)
	{
		_ = migrationBuilder.DropForeignKey(
			name: "FK_Accesses_Members_MemberId",
			table: "Accesses");

		_ = migrationBuilder.DropIndex(
			name: "IX_Accesses_AssetId",
			table: "Accesses");

		_ = migrationBuilder.DropIndex(
			name: "IX_Accesses_MemberId_AssetId",
			table: "Accesses");

		_ = migrationBuilder.RenameColumn(
			name: "MemberId",
			table: "Accesses",
			newName: "UserId");

		_ = migrationBuilder.CreateIndex(
			name: "IX_Accesses_AssetId_UserId",
			table: "Accesses",
			columns: new[] { "AssetId", "UserId" },
			unique: true);

		_ = migrationBuilder.CreateIndex(
			name: "IX_Accesses_UserId",
			table: "Accesses",
			column: "UserId");

		_ = migrationBuilder.AddForeignKey(
			name: "FK_Accesses_Users_UserId",
			table: "Accesses",
			column: "UserId",
			principalTable: "Users",
			principalColumn: "Id",
			onDelete: ReferentialAction.Cascade);
	}
}
