using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace MTWorkHR.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class altrOrderFK2 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_BusinessTripExpenses_OrderRequests_OrderRequestId",
                table: "BusinessTripExpenses");

            migrationBuilder.DropForeignKey(
                name: "FK_OverTimeDay_OrderRequests_OrderRequestId",
                table: "OverTimeDay");

            migrationBuilder.DropIndex(
                name: "IX_BusinessTripExpenses_OrderRequestId",
                table: "BusinessTripExpenses");

            migrationBuilder.AlterColumn<long>(
                name: "OrderRequestId",
                table: "OverTimeDay",
                type: "bigint",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "bigint");

            migrationBuilder.AlterColumn<long>(
                name: "OrderRequestId",
                table: "BusinessTripExpenses",
                type: "bigint",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "bigint");

            migrationBuilder.CreateIndex(
                name: "IX_BusinessTripExpenses_OrderRequestId",
                table: "BusinessTripExpenses",
                column: "OrderRequestId",
                unique: true,
                filter: "[OrderRequestId] IS NOT NULL");

            migrationBuilder.AddForeignKey(
                name: "FK_BusinessTripExpenses_OrderRequests_OrderRequestId",
                table: "BusinessTripExpenses",
                column: "OrderRequestId",
                principalTable: "OrderRequests",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_OverTimeDay_OrderRequests_OrderRequestId",
                table: "OverTimeDay",
                column: "OrderRequestId",
                principalTable: "OrderRequests",
                principalColumn: "Id");
        }

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

            migrationBuilder.DropForeignKey(
                name: "FK_OverTimeDay_OrderRequests_OrderRequestId",
                table: "OverTimeDay");

            migrationBuilder.DropIndex(
                name: "IX_BusinessTripExpenses_OrderRequestId",
                table: "BusinessTripExpenses");

            migrationBuilder.AlterColumn<long>(
                name: "OrderRequestId",
                table: "OverTimeDay",
                type: "bigint",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(long),
                oldType: "bigint",
                oldNullable: true);

            migrationBuilder.AlterColumn<long>(
                name: "OrderRequestId",
                table: "BusinessTripExpenses",
                type: "bigint",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(long),
                oldType: "bigint",
                oldNullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_BusinessTripExpenses_OrderRequestId",
                table: "BusinessTripExpenses",
                column: "OrderRequestId",
                unique: true);

            migrationBuilder.AddForeignKey(
                name: "FK_BusinessTripExpenses_OrderRequests_OrderRequestId",
                table: "BusinessTripExpenses",
                column: "OrderRequestId",
                principalTable: "OrderRequests",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OverTimeDay_OrderRequests_OrderRequestId",
                table: "OverTimeDay",
                column: "OrderRequestId",
                principalTable: "OrderRequests",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
