using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Ropin.Inspection.Model.Migrations
{
    public partial class EditSys : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "C_LicenseCode",
                table: "TasksQz",
                type: "varchar(50) CHARACTER SET utf8mb4",
                maxLength: 50,
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateTable(
                name: "TSYS_Message",
                columns: table => new
                {
                    C_Code = table.Column<Guid>(type: "char(36)", nullable: false),
                    C_LicenseCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_Type = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_Content = table.Column<string>(type: "varchar(1000) CHARACTER SET utf8mb4", maxLength: 1000, nullable: false),
                    C_UserID = table.Column<Guid>(type: "char(36)", nullable: false),
                    C_RelatedModule = table.Column<string>(type: "varchar(200) CHARACTER SET utf8mb4", maxLength: 200, nullable: true),
                    C_RelatedID = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: true),
                    C_CreateBy = table.Column<Guid>(type: "char(36)", nullable: false),
                    D_CreateOn = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    C_LastUpdatedBy = table.Column<Guid>(type: "char(36)", nullable: true),
                    D_LastUpdatedOn = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    C_Status = table.Column<string>(type: "varchar(1) CHARACTER SET utf8mb4", maxLength: 1, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TSYS_Message", x => x.C_Code);
                    table.ForeignKey(
                        name: "FK_TSYS_Message_TSYS_User_C_CreateBy",
                        column: x => x.C_CreateBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_TSYS_Message_TSYS_User_C_LastUpdatedBy",
                        column: x => x.C_LastUpdatedBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_TSYS_Message_TSYS_User_C_UserID",
                        column: x => x.C_UserID,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "TSYS_Version",
                columns: table => new
                {
                    C_ID = table.Column<Guid>(type: "char(36)", nullable: false),
                    C_AppCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_VersionCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_UpdateContent = table.Column<string>(type: "varchar(1000) CHARACTER SET utf8mb4", maxLength: 1000, nullable: false),
                    C_DownloadURL = table.Column<string>(type: "varchar(1000) CHARACTER SET utf8mb4", maxLength: 1000, nullable: false),
                    C_CreateBy = table.Column<Guid>(type: "char(36)", nullable: false),
                    D_CreateOn = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    C_LastUpdatedBy = table.Column<Guid>(type: "char(36)", nullable: true),
                    D_LastUpdatedOn = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    C_Status = table.Column<string>(type: "varchar(1) CHARACTER SET utf8mb4", maxLength: 1, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TSYS_Version", x => x.C_ID);
                    table.ForeignKey(
                        name: "FK_TSYS_Version_TSYS_User_C_CreateBy",
                        column: x => x.C_CreateBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_TSYS_Version_TSYS_User_C_LastUpdatedBy",
                        column: x => x.C_LastUpdatedBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_TSYS_Message_C_CreateBy",
                table: "TSYS_Message",
                column: "C_CreateBy");

            migrationBuilder.CreateIndex(
                name: "IX_TSYS_Message_C_LastUpdatedBy",
                table: "TSYS_Message",
                column: "C_LastUpdatedBy");

            migrationBuilder.CreateIndex(
                name: "IX_TSYS_Message_C_UserID",
                table: "TSYS_Message",
                column: "C_UserID");

            migrationBuilder.CreateIndex(
                name: "IX_TSYS_Version_C_CreateBy",
                table: "TSYS_Version",
                column: "C_CreateBy");

            migrationBuilder.CreateIndex(
                name: "IX_TSYS_Version_C_LastUpdatedBy",
                table: "TSYS_Version",
                column: "C_LastUpdatedBy");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "TSYS_Message");

            migrationBuilder.DropTable(
                name: "TSYS_Version");

            migrationBuilder.DropColumn(
                name: "C_LicenseCode",
                table: "TasksQz");
        }
    }
}