using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Demo2703.Migrations
{
    /// <inheritdoc />
    public partial class InitialCreate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.EnsureSchema(
                name: "demo2703");

            migrationBuilder.CreateTable(
                name: "gender",
                schema: "demo2703",
                columns: table => new
                {
                    code = table.Column<char>(type: "character(1)", maxLength: 1, nullable: false),
                    name = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("gender_pkey", x => x.code);
                });

            migrationBuilder.CreateTable(
                name: "manufacturer",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    startdate = table.Column<DateOnly>(type: "date", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("manufacturer_pkey", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "service",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    title = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    cost = table.Column<decimal>(type: "numeric(19,4)", precision: 19, scale: 4, nullable: false),
                    durationinseconds = table.Column<int>(type: "integer", nullable: false),
                    description = table.Column<string>(type: "text", nullable: true),
                    discount = table.Column<double>(type: "double precision", nullable: true),
                    mainimagepath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("service_pkey", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "tag",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    title = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
                    color = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("tag_pkey", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "client",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    firstname = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    lastname = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    patronymic = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    birthday = table.Column<DateOnly>(type: "date", nullable: true),
                    registrationdate = table.Column<DateOnly>(type: "date", nullable: false),
                    email = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
                    phone = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    gendercode = table.Column<char>(type: "character(1)", maxLength: 1, nullable: false),
                    photopath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("client_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_client_gender",
                        column: x => x.gendercode,
                        principalSchema: "demo2703",
                        principalTable: "gender",
                        principalColumn: "code");
                });

            migrationBuilder.CreateTable(
                name: "product",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    title = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    cost = table.Column<decimal>(type: "numeric(19,4)", precision: 19, scale: 4, nullable: false),
                    description = table.Column<string>(type: "text", nullable: true),
                    mainimagepath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
                    isactive = table.Column<int>(type: "integer", nullable: false),
                    manufacturerid = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("product_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_product_manufacturer",
                        column: x => x.manufacturerid,
                        principalSchema: "demo2703",
                        principalTable: "manufacturer",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "servicephoto",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    serviceid = table.Column<int>(type: "integer", nullable: false),
                    photopath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("servicephoto_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_servicephoto_service",
                        column: x => x.serviceid,
                        principalSchema: "demo2703",
                        principalTable: "service",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "clientservice",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    clientid = table.Column<int>(type: "integer", nullable: false),
                    serviceid = table.Column<int>(type: "integer", nullable: false),
                    starttime = table.Column<DateOnly>(type: "date", nullable: false),
                    comment = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("clientservice_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_clientservice_client",
                        column: x => x.clientid,
                        principalSchema: "demo2703",
                        principalTable: "client",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "fk_clientservice_service",
                        column: x => x.serviceid,
                        principalSchema: "demo2703",
                        principalTable: "service",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "tagofclient",
                schema: "demo2703",
                columns: table => new
                {
                    clientid = table.Column<int>(type: "integer", nullable: false),
                    tagid = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("tagofclient_pkey", x => new { x.clientid, x.tagid });
                    table.ForeignKey(
                        name: "fk_tagofclient_client",
                        column: x => x.clientid,
                        principalSchema: "demo2703",
                        principalTable: "client",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "fk_tagofclient_tag",
                        column: x => x.tagid,
                        principalSchema: "demo2703",
                        principalTable: "tag",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "attachedproduct",
                schema: "demo2703",
                columns: table => new
                {
                    mainproductid = table.Column<int>(type: "integer", nullable: false),
                    attachedproductid = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("attachedproduct_pkey", x => new { x.mainproductid, x.attachedproductid });
                    table.ForeignKey(
                        name: "fk_attachedproduct_product",
                        column: x => x.mainproductid,
                        principalSchema: "demo2703",
                        principalTable: "product",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "fk_attachedproduct_product1",
                        column: x => x.attachedproductid,
                        principalSchema: "demo2703",
                        principalTable: "product",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "productphoto",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    productid = table.Column<int>(type: "integer", nullable: false),
                    photopath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("productphoto_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_productphoto_product",
                        column: x => x.productid,
                        principalSchema: "demo2703",
                        principalTable: "product",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "documentbyservice",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    clientserviceid = table.Column<int>(type: "integer", nullable: false),
                    documentpath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("documentbyservice_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_documentbyservice_clientservice",
                        column: x => x.clientserviceid,
                        principalSchema: "demo2703",
                        principalTable: "clientservice",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "productsale",
                schema: "demo2703",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    saledate = table.Column<DateOnly>(type: "date", nullable: false),
                    productid = table.Column<int>(type: "integer", nullable: false),
                    quantity = table.Column<int>(type: "integer", nullable: false),
                    clientserviceid = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("productsale_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_productsale_clientservice",
                        column: x => x.clientserviceid,
                        principalSchema: "demo2703",
                        principalTable: "clientservice",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "fk_productsale_product",
                        column: x => x.productid,
                        principalSchema: "demo2703",
                        principalTable: "product",
                        principalColumn: "id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_attachedproduct_attachedproductid",
                schema: "demo2703",
                table: "attachedproduct",
                column: "attachedproductid");

            migrationBuilder.CreateIndex(
                name: "IX_client_gendercode",
                schema: "demo2703",
                table: "client",
                column: "gendercode");

            migrationBuilder.CreateIndex(
                name: "IX_clientservice_clientid",
                schema: "demo2703",
                table: "clientservice",
                column: "clientid");

            migrationBuilder.CreateIndex(
                name: "IX_clientservice_serviceid",
                schema: "demo2703",
                table: "clientservice",
                column: "serviceid");

            migrationBuilder.CreateIndex(
                name: "IX_documentbyservice_clientserviceid",
                schema: "demo2703",
                table: "documentbyservice",
                column: "clientserviceid");

            migrationBuilder.CreateIndex(
                name: "IX_product_manufacturerid",
                schema: "demo2703",
                table: "product",
                column: "manufacturerid");

            migrationBuilder.CreateIndex(
                name: "IX_productphoto_productid",
                schema: "demo2703",
                table: "productphoto",
                column: "productid");

            migrationBuilder.CreateIndex(
                name: "IX_productsale_clientserviceid",
                schema: "demo2703",
                table: "productsale",
                column: "clientserviceid");

            migrationBuilder.CreateIndex(
                name: "IX_productsale_productid",
                schema: "demo2703",
                table: "productsale",
                column: "productid");

            migrationBuilder.CreateIndex(
                name: "IX_servicephoto_serviceid",
                schema: "demo2703",
                table: "servicephoto",
                column: "serviceid");

            migrationBuilder.CreateIndex(
                name: "IX_tagofclient_tagid",
                schema: "demo2703",
                table: "tagofclient",
                column: "tagid");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "attachedproduct",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "documentbyservice",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "productphoto",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "productsale",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "servicephoto",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "tagofclient",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "clientservice",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "product",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "tag",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "client",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "service",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "manufacturer",
                schema: "demo2703");

            migrationBuilder.DropTable(
                name: "gender",
                schema: "demo2703");
        }
    }
}
