using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Gremlin.Migrations
{
    public partial class InitialCreate : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AccountTypes",
                columns: table => new
                {
                    AccountTypeCode = table.Column<string>(type: "Char(3)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataValidFrom = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataValidUntil = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "'9999-12-31 23:59:59.000000'"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataVersionNumber = table.Column<uint>(type: "int unsigned", nullable: false, defaultValue: 1u),
                    DataVersionComment = table.Column<string>(type: "longtext", nullable: true, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataStatus = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    AccountTypeDescription = table.Column<string>(type: "Varchar(1000)", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AccountTypes", x => x.AccountTypeCode);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ProductLines",
                columns: table => new
                {
                    ProductLineId = table.Column<uint>(type: "int unsigned", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataValidFrom = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataValidUntil = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "'9999-12-31 23:59:59.000000'"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataVersionNumber = table.Column<uint>(type: "int unsigned", nullable: false, defaultValue: 1u),
                    DataVersionComment = table.Column<string>(type: "longtext", nullable: true, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataStatus = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProductLineAbbreviation = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProductLineDescription = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProductLines", x => x.ProductLineId);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "RegisteredUser",
                columns: table => new
                {
                    RegisteredUserID = table.Column<uint>(type: "int unsigned", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UserName = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PasswordHash = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RegisteredUser", x => x.RegisteredUserID);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "SubMarkets",
                columns: table => new
                {
                    SubMarketCode = table.Column<string>(type: "Char(3)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataValidFrom = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataValidUntil = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "'9999-12-31 23:59:59.000000'"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataVersionNumber = table.Column<uint>(type: "int unsigned", nullable: false, defaultValue: 1u),
                    DataVersionComment = table.Column<string>(type: "longtext", nullable: true, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataStatus = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SubMarketDescription = table.Column<string>(type: "Varchar(1000)", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SubMarkets", x => x.SubMarketCode);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Products",
                columns: table => new
                {
                    ProductId = table.Column<uint>(type: "int unsigned", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataValidFrom = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataValidUntil = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "'9999-12-31 23:59:59.000000'"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataVersionNumber = table.Column<uint>(type: "int unsigned", nullable: false, defaultValue: 1u),
                    DataVersionComment = table.Column<string>(type: "longtext", nullable: true, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataStatus = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProductLineId = table.Column<uint>(type: "int unsigned", nullable: true),
                    ProductNumber = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OptionNumber = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SapShortDescription = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SapLongDescription = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Weight = table.Column<float>(type: "float", nullable: false),
                    ProductStatus = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IntroductionDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ListPrice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    HasBreakPrices = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    BreakRangeFrom = table.Column<int>(type: "int", nullable: false),
                    BreakRangeTo = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Products", x => x.ProductId);
                    table.ForeignKey(
                        name: "FK_Products_ProductLines_ProductLineId",
                        column: x => x.ProductLineId,
                        principalTable: "ProductLines",
                        principalColumn: "ProductLineId",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "RUSettings",
                columns: table => new
                {
                    RUSettingsID = table.Column<uint>(type: "int unsigned", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    RegisteredUserID = table.Column<uint>(type: "int unsigned", nullable: false),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SettingKey = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SettingValue = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RUSettings", x => x.RUSettingsID);
                    table.ForeignKey(
                        name: "FK_RUSettings_RegisteredUser_RegisteredUserID",
                        column: x => x.RegisteredUserID,
                        principalTable: "RegisteredUser",
                        principalColumn: "RegisteredUserID",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Accounts",
                columns: table => new
                {
                    AccountId = table.Column<uint>(type: "int unsigned", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ParentAccountId = table.Column<int>(type: "int", nullable: true),
                    AccountTypeCode = table.Column<string>(type: "Char(3)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SubMarketCode = table.Column<string>(type: "Char(3)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataValidFrom = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataValidUntil = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "'9999-12-31 23:59:59.000000'"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataVersionNumber = table.Column<uint>(type: "int unsigned", nullable: false, defaultValue: 1u),
                    DataVersionComment = table.Column<string>(type: "longtext", nullable: true, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataStatus = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    AccountName = table.Column<string>(type: "varchar(250)", maxLength: 250, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Notes = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Street = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ZIP = table.Column<string>(type: "Char(5)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    City = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    FloorOrBuilding = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Longitude = table.Column<float>(type: "float", nullable: false),
                    Latitude = table.Column<float>(type: "float", nullable: false),
                    PhoneNumber = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    FaxNumber = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Webpage = table.Column<string>(type: "varchar(250)", maxLength: 250, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    EMail = table.Column<string>(type: "varchar(150)", maxLength: 150, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SAPAccountNumber = table.Column<uint>(type: "int unsigned", nullable: false),
                    AccountCreatedinSAPOn = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Accounts", x => x.AccountId);
                    table.UniqueConstraint("AK_Accounts_SAPAccountNumber", x => x.SAPAccountNumber);
                    table.ForeignKey(
                        name: "FK_Accounts_AccountTypes_AccountTypeCode",
                        column: x => x.AccountTypeCode,
                        principalTable: "AccountTypes",
                        principalColumn: "AccountTypeCode",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Accounts_SubMarkets_SubMarketCode",
                        column: x => x.SubMarketCode,
                        principalTable: "SubMarkets",
                        principalColumn: "SubMarketCode",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Contacts",
                columns: table => new
                {
                    ContactId = table.Column<uint>(type: "int unsigned", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    AccountId = table.Column<uint>(type: "int unsigned", nullable: false),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataValidFrom = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataValidUntil = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "'9999-12-31 23:59:59.000000'"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataVersionNumber = table.Column<uint>(type: "int unsigned", nullable: false, defaultValue: 1u),
                    DataVersionComment = table.Column<string>(type: "longtext", nullable: true, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataStatus = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    AcademicTitle = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    FirstName = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastName = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Gender = table.Column<byte>(type: "tinyint unsigned", nullable: false),
                    OptInStatus = table.Column<bool>(type: "tinyint(1)", nullable: true),
                    Department = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Function = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Room = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsReference = table.Column<bool>(type: "tinyint(1)", nullable: true, defaultValue: false),
                    Notes = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PhoneNumber = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MobileNumber = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    EMail = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PreferredContactMethod = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    NoPhoneCalls = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    EmailBounced = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    NoHardcopyMailing = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    ValidatedContact = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false),
                    SAPContactNumber = table.Column<int>(type: "int", nullable: false),
                    SAPContactCreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    SAPContactModifiedDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    SAPJobFunction = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SAPProductInterest = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SAPApplicationInterest = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SAPJobLevel = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SAPCompetitiveIBase = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LinkToSAP = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Contacts", x => x.ContactId);
                    table.ForeignKey(
                        name: "FK_Contacts_Accounts_AccountId",
                        column: x => x.AccountId,
                        principalTable: "Accounts",
                        principalColumn: "AccountId",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "CustomDescriptions",
                columns: table => new
                {
                    CustomDescriptionId = table.Column<uint>(type: "int unsigned", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ProductId = table.Column<uint>(type: "int unsigned", nullable: false),
                    AccountId = table.Column<uint>(type: "int unsigned", nullable: false),
                    DataCreationDate = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModificationDate = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    DataValidFrom = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataValidUntil = table.Column<DateTime>(type: "DATETIME", nullable: false, defaultValueSql: "'9999-12-31 23:59:59.000000'"),
                    DataModificationByUser = table.Column<string>(type: "TINYTEXT", nullable: true, defaultValueSql: "ON INSERT CURRENT_USER() ON UPDATE CURRENT_USER()")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataVersionNumber = table.Column<uint>(type: "int unsigned", nullable: false, defaultValue: 1u),
                    DataVersionComment = table.Column<string>(type: "longtext", nullable: true, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataStatus = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProductNumber = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OptionNumber = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Heading = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DescriptionText = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CoverletterText = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Note = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CustomDescriptions", x => x.CustomDescriptionId);
                    table.ForeignKey(
                        name: "FK_CustomDescriptions_Accounts_AccountId",
                        column: x => x.AccountId,
                        principalTable: "Accounts",
                        principalColumn: "AccountId",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_CustomDescriptions_Products_ProductId",
                        column: x => x.ProductId,
                        principalTable: "Products",
                        principalColumn: "ProductId",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Quotes",
                columns: table => new
                {
                    QuoteId = table.Column<uint>(type: "int unsigned", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    DataCreated = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModified = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    QuotationNumber = table.Column<string>(type: "VARCHAR(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    QuotationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ValidUntil = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ValidFor = table.Column<byte>(type: "tinyint unsigned", nullable: false),
                    RecipientContactId = table.Column<uint>(type: "int unsigned", nullable: true),
                    TotalListprice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    TotalDiscount = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    TotalNet = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    VAT = table.Column<float>(type: "float", nullable: false),
                    TotalGross = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    QuoteContains3PP = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false),
                    QuoteContainsRB = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false),
                    QuoteTemplate = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Quotes", x => x.QuoteId);
                    table.ForeignKey(
                        name: "FK_Quotes_Contacts_RecipientContactId",
                        column: x => x.RecipientContactId,
                        principalTable: "Contacts",
                        principalColumn: "ContactId",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "LineItems",
                columns: table => new
                {
                    QuoteId = table.Column<uint>(type: "int unsigned", nullable: false),
                    LineItemId = table.Column<uint>(type: "int unsigned", nullable: false),
                    DataCreated = table.Column<DateTime>(type: "TIMESTAMP", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    DataModified = table.Column<DateTime>(type: "TIMESTAMP", rowVersion: true, nullable: false, defaultValueSql: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
                    Position = table.Column<ushort>(type: "smallint unsigned", nullable: false),
                    Amount = table.Column<ushort>(type: "smallint unsigned", nullable: false),
                    ProductNumber = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OptionNumber = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SapShortDescription = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SapLongDescription = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProductLine = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    TotalDiscount = table.Column<decimal>(type: "decimal(65,30)", nullable: false, defaultValue: 0m),
                    SalesDiscount = table.Column<decimal>(type: "decimal(65,30)", nullable: false, defaultValue: 0m),
                    PromotionalDiscount = table.Column<decimal>(type: "decimal(65,30)", nullable: false, defaultValue: 0m),
                    ContractualDiscount = table.Column<decimal>(type: "decimal(65,30)", nullable: false, defaultValue: 0m),
                    DemoDiscount = table.Column<decimal>(type: "decimal(65,30)", nullable: false, defaultValue: 0m),
                    ListPrice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    ExtendedListPrice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    NetPrice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    Total = table.Column<decimal>(type: "decimal(65,30)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LineItems", x => x.QuoteId);
                    table.ForeignKey(
                        name: "FK_LineItems_Quotes_QuoteId",
                        column: x => x.QuoteId,
                        principalTable: "Quotes",
                        principalColumn: "QuoteId",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Accounts_AccountTypeCode",
                table: "Accounts",
                column: "AccountTypeCode");

            migrationBuilder.CreateIndex(
                name: "IX_Accounts_SubMarketCode",
                table: "Accounts",
                column: "SubMarketCode");

            migrationBuilder.CreateIndex(
                name: "IX_Contacts_AccountId",
                table: "Contacts",
                column: "AccountId");

            migrationBuilder.CreateIndex(
                name: "IX_CustomDescriptions_AccountId",
                table: "CustomDescriptions",
                column: "AccountId");

            migrationBuilder.CreateIndex(
                name: "IX_CustomDescriptions_ProductId",
                table: "CustomDescriptions",
                column: "ProductId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Products_ProductLineId",
                table: "Products",
                column: "ProductLineId");

            migrationBuilder.CreateIndex(
                name: "IX_Quotes_RecipientContactId",
                table: "Quotes",
                column: "RecipientContactId");

            migrationBuilder.CreateIndex(
                name: "IX_RUSettings_RegisteredUserID",
                table: "RUSettings",
                column: "RegisteredUserID");
        }

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

            migrationBuilder.DropTable(
                name: "LineItems");

            migrationBuilder.DropTable(
                name: "RUSettings");

            migrationBuilder.DropTable(
                name: "Products");

            migrationBuilder.DropTable(
                name: "Quotes");

            migrationBuilder.DropTable(
                name: "RegisteredUser");

            migrationBuilder.DropTable(
                name: "ProductLines");

            migrationBuilder.DropTable(
                name: "Contacts");

            migrationBuilder.DropTable(
                name: "Accounts");

            migrationBuilder.DropTable(
                name: "AccountTypes");

            migrationBuilder.DropTable(
                name: "SubMarkets");
        }
    }
}
