using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Monitoring.Infrastructure.Data.Migrations;

/// <inheritdoc />
public partial class AddAccesses : Migration
{
	/// <inheritdoc />
	protected override void Up(MigrationBuilder migrationBuilder)
	{
		_ = migrationBuilder.CreateTable(
			name: "Accesses",
			columns: table => new
			{
				Id = table.Column<Guid>(type: "uuid", nullable: false),
				UserId = table.Column<Guid>(type: "uuid", nullable: false),
				AssetId = table.Column<Guid>(type: "uuid", nullable: false)
			},
			constraints: table =>
			{
				_ = table.PrimaryKey("PK_Accesses", x => x.Id);
				_ = table.ForeignKey(
					name: "FK_Accesses_Assets_AssetId",
					column: x => x.AssetId,
					principalTable: "Assets",
					principalColumn: "Id",
					onDelete: ReferentialAction.Cascade);
				_ = table.ForeignKey(
					name: "FK_Accesses_Users_UserId",
					column: x => x.UserId,
					principalTable: "Users",
					principalColumn: "Id",
					onDelete: ReferentialAction.Cascade);
			});

		_ = 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");
	}

	/// <inheritdoc />
	protected override void Down(MigrationBuilder migrationBuilder)
	{
		_ = migrationBuilder.DropTable(
			name: "Accesses");
	}
}
