using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace RB_MES_APICore.Migrations
{
    /// <inheritdoc />
    public partial class updateInfoV1 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "r_JoinTb");

            migrationBuilder.DropTable(
                name: "r_K3DefaultColVals");

            migrationBuilder.DropTable(
                name: "r_MesRequestStatus");

            migrationBuilder.DropTable(
                name: "r_SCol");

            migrationBuilder.DropColumn(
                name: "FIsDetail",
                table: "r_FunctionList");

            migrationBuilder.AlterColumn<string>(
                name: "FSource",
                table: "RBLog",
                type: "nvarchar(max)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "xml");

            migrationBuilder.AlterColumn<string>(
                name: "FMess",
                table: "RBLog",
                type: "nvarchar(max)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(255)",
                oldMaxLength: 255);

            migrationBuilder.AlterColumn<string>(
                name: "FDocType",
                table: "RBLog",
                type: "nvarchar(200)",
                maxLength: 200,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(80)",
                oldMaxLength: 80);

            migrationBuilder.AddColumn<string>(
                name: "FGUID",
                table: "RBLog",
                type: "nvarchar(max)",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "FGuidColName",
                table: "r_FormIDType",
                type: "nvarchar(100)",
                maxLength: 100,
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "FNeedBreakSQL",
                table: "r_FormIDType",
                type: "nvarchar(500)",
                maxLength: 500,
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<int>(
                name: "FIndexID",
                table: "r_ClumnConvert",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "r_ApiHostServices",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FActionName = table.Column<string>(type: "nvarchar(80)", maxLength: 80, nullable: false),
                    FDocType = table.Column<string>(type: "nvarchar(80)", maxLength: 80, nullable: false),
                    FTimer = table.Column<int>(type: "int", maxLength: 80, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_ApiHostServices", x => x.FID);
                });

            migrationBuilder.CreateTable(
                name: "r_BillTypeRules",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FPostTypeID = table.Column<string>(type: "nvarchar(80)", maxLength: 80, nullable: false),
                    FSBillTypeNumber = table.Column<string>(type: "nvarchar(80)", maxLength: 80, nullable: false),
                    FDBillTypeNumber = table.Column<string>(type: "nvarchar(80)", maxLength: 80, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_BillTypeRules", x => x.FID);
                });

            migrationBuilder.CreateTable(
                name: "r_CustomServices",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FApiGroupID = table.Column<int>(type: "int", maxLength: 255, nullable: false),
                    FNamespace = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
                    FClassName = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
                    FActionName = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
                    FAppComponents = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_CustomServices", x => x.FID);
                    table.ForeignKey(
                        name: "FK_r_CustomServices_APIGrou_FApiGroupID",
                        column: x => x.FApiGroupID,
                        principalTable: "APIGrou",
                        principalColumn: "FID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "r_DataSaveBatch",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FDocTypeID = table.Column<int>(type: "int", nullable: false),
                    FNumberSearch = table.Column<bool>(type: "bit", nullable: false),
                    FValidateFlag = table.Column<bool>(type: "bit", nullable: false),
                    FIsDeleteEntry = table.Column<bool>(type: "bit", nullable: false),
                    FIsEntryBatchFill = table.Column<bool>(type: "bit", nullable: false),
                    FNeedUpDateFields = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FNeedReturnFields = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FSubSystemId = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FInterationFlags = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FIsAutoSubmitAndAudit = table.Column<bool>(type: "bit", nullable: false),
                    FBatchCount = table.Column<int>(type: "int", nullable: false),
                    FIsVerifyBaseDataField = table.Column<bool>(type: "bit", nullable: false),
                    FIsAutoAdjustField = table.Column<bool>(type: "bit", nullable: false),
                    FIgnoreInterationFlag = table.Column<bool>(type: "bit", nullable: false),
                    FIsControlPrecision = table.Column<bool>(type: "bit", nullable: false),
                    FValidateRepeatJson = table.Column<bool>(type: "bit", nullable: false),
                    FSubmitUrl = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
                    FAuditUrl = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
                    FErpBillType = table.Column<string>(type: "nvarchar(max)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_DataSaveBatch", x => x.FID);
                    table.ForeignKey(
                        name: "FK_r_DataSaveBatch_r_FormIDType_FDocTypeID",
                        column: x => x.FDocTypeID,
                        principalTable: "r_FormIDType",
                        principalColumn: "FID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "r_LockPRD_MO",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ERP_MO = table.Column<string>(type: "nvarchar(36)", maxLength: 36, nullable: false),
                    MO_SEQ = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    MOID = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    MOEntryID = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    TRX_DATE = table.Column<string>(type: "nvarchar(max)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_LockPRD_MO", x => x.FID);
                });

            migrationBuilder.CreateTable(
                name: "r_ReciveDataBack",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FDocType = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    FBillNo = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FErpID = table.Column<int>(type: "int", nullable: false),
                    FSeq = table.Column<int>(type: "int", nullable: false),
                    QUEUE_ID = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FJson = table.Column<string>(type: "nvarchar(max)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_ReciveDataBack", x => x.FID);
                });

            migrationBuilder.CreateTable(
                name: "t_AuthorizationInfo",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FAppKey = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FAppSecret = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FAuthCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FAppTicket = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FUserCode = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FUserAuthPermanentCode = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FAppAccessToken = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FOrgAuthTempCode = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FOrgAuthPermanentCode = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FOrgAccessToken = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FToken = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FStartDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    FExpireDate = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_AuthorizationInfo", x => x.FID);
                });

            migrationBuilder.CreateIndex(
                name: "IX_r_BillTypeRules_FPostTypeID_FSBillTypeNumber",
                table: "r_BillTypeRules",
                columns: new[] { "FPostTypeID", "FSBillTypeNumber" });

            migrationBuilder.CreateIndex(
                name: "IX_r_CustomServices_FApiGroupID",
                table: "r_CustomServices",
                column: "FApiGroupID");

            migrationBuilder.CreateIndex(
                name: "IX_r_DataSaveBatch_FDocTypeID",
                table: "r_DataSaveBatch",
                column: "FDocTypeID");

            migrationBuilder.CreateIndex(
                name: "IX_r_LockPRD_MO_ERP_MO_MO_SEQ",
                table: "r_LockPRD_MO",
                columns: new[] { "ERP_MO", "MO_SEQ" });

            migrationBuilder.CreateIndex(
                name: "IX_r_ReciveDataBack_FDocType_FErpID_FSeq",
                table: "r_ReciveDataBack",
                columns: new[] { "FDocType", "FErpID", "FSeq" },
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "r_ApiHostServices");

            migrationBuilder.DropTable(
                name: "r_BillTypeRules");

            migrationBuilder.DropTable(
                name: "r_CustomServices");

            migrationBuilder.DropTable(
                name: "r_DataSaveBatch");

            migrationBuilder.DropTable(
                name: "r_LockPRD_MO");

            migrationBuilder.DropTable(
                name: "r_ReciveDataBack");

            migrationBuilder.DropTable(
                name: "t_AuthorizationInfo");

            migrationBuilder.DropColumn(
                name: "FGUID",
                table: "RBLog");

            migrationBuilder.DropColumn(
                name: "FGuidColName",
                table: "r_FormIDType");

            migrationBuilder.DropColumn(
                name: "FNeedBreakSQL",
                table: "r_FormIDType");

            migrationBuilder.DropColumn(
                name: "FIndexID",
                table: "r_ClumnConvert");

            migrationBuilder.AlterColumn<string>(
                name: "FSource",
                table: "RBLog",
                type: "xml",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)");

            migrationBuilder.AlterColumn<string>(
                name: "FMess",
                table: "RBLog",
                type: "nvarchar(255)",
                maxLength: 255,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)");

            migrationBuilder.AlterColumn<string>(
                name: "FDocType",
                table: "RBLog",
                type: "nvarchar(80)",
                maxLength: 80,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(200)",
                oldMaxLength: 200);

            migrationBuilder.AddColumn<bool>(
                name: "FIsDetail",
                table: "r_FunctionList",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.CreateTable(
                name: "r_JoinTb",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FSID = table.Column<int>(type: "int", nullable: false),
                    FAsName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    FCondition = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
                    FCtlID = table.Column<int>(type: "int", nullable: false),
                    FJoinSymbol = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    FJoinType = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    FTbName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_JoinTb", x => x.FID);
                    table.ForeignKey(
                        name: "FK_r_JoinTb_r_SelectJoinID_FSID",
                        column: x => x.FSID,
                        principalTable: "r_SelectJoinID",
                        principalColumn: "FID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "r_K3DefaultColVals",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FReceiveID = table.Column<int>(type: "int", nullable: false),
                    FDescribe = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FPageID = table.Column<int>(type: "int", nullable: false),
                    FSqlType = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    FVal = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    K3FiledName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_K3DefaultColVals", x => x.FID);
                    table.ForeignKey(
                        name: "FK_r_K3DefaultColVals_r_ReceiveStockBillTypes_FReceiveID",
                        column: x => x.FReceiveID,
                        principalTable: "r_ReceiveStockBillTypes",
                        principalColumn: "FID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "r_MesRequestStatus",
                columns: table => new
                {
                    FID = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    FERPBillType = table.Column<int>(type: "int", nullable: false),
                    FERPBillID = table.Column<int>(type: "int", nullable: false),
                    FERPBillEntryID = table.Column<int>(type: "int", nullable: false),
                    FIMSDocType = table.Column<string>(type: "nvarchar(80)", maxLength: 80, nullable: false),
                    FRequestKey = table.Column<string>(type: "nvarchar(80)", maxLength: 80, nullable: false),
                    FStatus = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_MesRequestStatus", x => new { x.FID, x.FERPBillType, x.FERPBillID, x.FERPBillEntryID });
                });

            migrationBuilder.CreateTable(
                name: "r_SCol",
                columns: table => new
                {
                    FID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    FSID = table.Column<int>(type: "int", nullable: false),
                    FAsName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    FAsTable = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    FColName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    FCtlID = table.Column<int>(type: "int", nullable: false),
                    FDeaful = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_r_SCol", x => x.FID);
                    table.ForeignKey(
                        name: "FK_r_SCol_r_SelectJoinID_FSID",
                        column: x => x.FSID,
                        principalTable: "r_SelectJoinID",
                        principalColumn: "FID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_r_JoinTb_FSID_FCtlID",
                table: "r_JoinTb",
                columns: new[] { "FSID", "FCtlID" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_r_K3DefaultColVals_FReceiveID_FPageID_K3FiledName",
                table: "r_K3DefaultColVals",
                columns: new[] { "FReceiveID", "FPageID", "K3FiledName" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_r_SCol_FSID_FAsName",
                table: "r_SCol",
                columns: new[] { "FSID", "FAsName" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_r_SCol_FSID_FCtlID",
                table: "r_SCol",
                columns: new[] { "FSID", "FCtlID" },
                unique: true);
        }
    }
}
