using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

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

            migrationBuilder.DropForeignKey(
                name: "FK_OrderRequests_ServiceCertificate_ServiceCertificateId",
                table: "OrderRequests");

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

            migrationBuilder.DropIndex(
                name: "IX_OrderRequests_BusinessTripExpensesId",
                table: "OrderRequests");

            migrationBuilder.DropIndex(
                name: "IX_OrderRequests_ServiceCertificateId",
                table: "OrderRequests");

            migrationBuilder.DropColumn(
                name: "BusinessTripExpensesId",
                table: "OrderRequests");

            migrationBuilder.DropColumn(
                name: "ServiceCertificateId",
                table: "OrderRequests");

            migrationBuilder.AddColumn<long>(
                name: "OrderRequestId",
                table: "ServiceCertificate",
                type: "bigint",
                nullable: false,
                defaultValue: 0L);

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

            migrationBuilder.AddColumn<long>(
                name: "OrderRequestId",
                table: "BusinessTripExpenses",
                type: "bigint",
                nullable: false,
                defaultValue: 0L);

            migrationBuilder.CreateIndex(
                name: "IX_ServiceCertificate_OrderRequestId",
                table: "ServiceCertificate",
                column: "OrderRequestId",
                unique: 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);

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

        /// <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.DropForeignKey(
                name: "FK_ServiceCertificate_OrderRequests_OrderRequestId",
                table: "ServiceCertificate");

            migrationBuilder.DropIndex(
                name: "IX_ServiceCertificate_OrderRequestId",
                table: "ServiceCertificate");

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

            migrationBuilder.DropColumn(
                name: "OrderRequestId",
                table: "ServiceCertificate");

            migrationBuilder.DropColumn(
                name: "OrderRequestId",
                table: "BusinessTripExpenses");

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

            migrationBuilder.AddColumn<long>(
                name: "BusinessTripExpensesId",
                table: "OrderRequests",
                type: "bigint",
                nullable: true);

            migrationBuilder.AddColumn<long>(
                name: "ServiceCertificateId",
                table: "OrderRequests",
                type: "bigint",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_OrderRequests_BusinessTripExpensesId",
                table: "OrderRequests",
                column: "BusinessTripExpensesId");

            migrationBuilder.CreateIndex(
                name: "IX_OrderRequests_ServiceCertificateId",
                table: "OrderRequests",
                column: "ServiceCertificateId");

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

            migrationBuilder.AddForeignKey(
                name: "FK_OrderRequests_ServiceCertificate_ServiceCertificateId",
                table: "OrderRequests",
                column: "ServiceCertificateId",
                principalTable: "ServiceCertificate",
                principalColumn: "Id");

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