stylist / backend / Stylist.Data / Migrations / 20240118160748_InitialMigration.cs
20240118160748_InitialMigration.cs
Raw
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace Stylist.Data.Migrations
{
    /// <inheritdoc />
    public partial class InitialMigration : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Hairdressers",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "text", nullable: false),
                    ImageUrl = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Hairdressers", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainServices",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainServices", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Salons",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    Adress = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    AdressUrl = table.Column<string>(type: "text", nullable: true),
                    Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
                    PhoneNumber = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
                    WebsiteUrl = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    ImageUrls = table.Column<string>(type: "text", nullable: true),
                    Gender = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Salons", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Users",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    FirstName = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    LastName = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    UserName = table.Column<string>(type: "text", nullable: false),
                    Password = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    Email = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    PhoneNumber = table.Column<string>(type: "text", nullable: true),
                    ImageUrl = table.Column<string>(type: "text", nullable: true),
                    Gender = table.Column<int>(type: "integer", nullable: true),
                    Role = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Users", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Schedules",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Starts = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    Ends = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    HairdresserId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Schedules", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Schedules_Hairdressers_HairdresserId",
                        column: x => x.HairdresserId,
                        principalTable: "Hairdressers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Services",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: true),
                    Duration = table.Column<int>(type: "integer", nullable: false),
                    Price = table.Column<double>(type: "double precision", nullable: false),
                    Gender = table.Column<int>(type: "integer", nullable: false),
                    SalonId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Services", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Services_Salons_SalonId",
                        column: x => x.SalonId,
                        principalTable: "Salons",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "WorkingHours",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    IsWorkingDay = table.Column<bool>(type: "boolean", nullable: false),
                    OpeningHour = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    ClosingHour = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    SalonId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WorkingHours", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WorkingHours_Salons_SalonId",
                        column: x => x.SalonId,
                        principalTable: "Salons",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "HairdresserServices",
                columns: table => new
                {
                    HairdresserId = table.Column<int>(type: "integer", nullable: false),
                    ServiceId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_HairdresserServices", x => new { x.HairdresserId, x.ServiceId });
                    table.ForeignKey(
                        name: "FK_HairdresserServices_Hairdressers_HairdresserId",
                        column: x => x.HairdresserId,
                        principalTable: "Hairdressers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_HairdresserServices_Services_ServiceId",
                        column: x => x.ServiceId,
                        principalTable: "Services",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Reservations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Note = table.Column<string>(type: "text", nullable: true),
                    Price = table.Column<double>(type: "double precision", nullable: false),
                    Starts = table.Column<TimeOnly>(type: "time without time zone", nullable: false),
                    Ends = table.Column<TimeOnly>(type: "time without time zone", nullable: false),
                    ScheduleId = table.Column<int>(type: "integer", nullable: false),
                    ServiceId = table.Column<int>(type: "integer", nullable: false),
                    UserId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Reservations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Reservations_Schedules_ScheduleId",
                        column: x => x.ScheduleId,
                        principalTable: "Schedules",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Reservations_Services_ServiceId",
                        column: x => x.ServiceId,
                        principalTable: "Services",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Reservations_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ServiceMainServices",
                columns: table => new
                {
                    MainServiceId = table.Column<int>(type: "integer", nullable: false),
                    ServiceId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ServiceMainServices", x => new { x.ServiceId, x.MainServiceId });
                    table.ForeignKey(
                        name: "FK_ServiceMainServices_MainServices_MainServiceId",
                        column: x => x.MainServiceId,
                        principalTable: "MainServices",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ServiceMainServices_Services_ServiceId",
                        column: x => x.ServiceId,
                        principalTable: "Services",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Reviews",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Comment = table.Column<string>(type: "text", nullable: false),
                    Rating = table.Column<int>(type: "integer", nullable: false),
                    Date = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    ReservationId = table.Column<int>(type: "integer", nullable: false),
                    SalonId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Reviews", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Reviews_Reservations_ReservationId",
                        column: x => x.ReservationId,
                        principalTable: "Reservations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Reviews_Salons_SalonId",
                        column: x => x.SalonId,
                        principalTable: "Salons",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "Hairdressers",
                columns: new[] { "Id", "ImageUrl", "Name" },
                values: new object[,]
                {
                    { 1, "https://hayat.ba/wp-content/uploads/2023/09/baka-mare-srecko.jpg", "Mare Friz" },
                    { 2, "https://media.licdn.com/dms/image/C4D03AQHL-3hSlUDlBQ/profile-displayphoto-shrink_800_800/0/1657973397140?e=2147483647&v=beta&t=e3QL6yqT7GqvXFRjOXw4trVOvCqNOOYZD_xzzMT1U38", "Ante Ludi Friz" }
                });

            migrationBuilder.InsertData(
                table: "MainServices",
                columns: new[] { "Id", "Name" },
                values: new object[,]
                {
                    { 1, "Kratko sisanje" },
                    { 2, "Pranje kose" }
                });

            migrationBuilder.InsertData(
                table: "Salons",
                columns: new[] { "Id", "Adress", "AdressUrl", "Description", "Gender", "ImageUrls", "Name", "PhoneNumber", "WebsiteUrl" },
                values: new object[,]
                {
                    { 1, "ul. Antofagaste 12", "https://www.google.com/maps/place//data=!4m2!3m1!1s0x13355da6fb3e8f57:0xbb9c2e8f457892a0?sa=X&ved=2ahUKEwjk1sPi1c2DAxXsFhAIHRRUCIkQ4kB6BAgAEAA", "Description", 1, "slike", "Mare frizerka", "123123", "https://www.google.hr" },
                    { 2, "ul. Antofagaste 12", "https://www.google.com/maps/place//data=!4m2!3m1!1s0x13355da6fb3e8f57:0xbb9c2e8f457892a0?sa=X&ved=2ahUKEwjk1sPi1c2DAxXsFhAIHRRUCIkQ4kB6BAgAEAA", "Description", 0, "slike", "Mare i frizeri", "123123", "https://www.google.hr" },
                    { 3, "ul. Maticica Ludog 12", "https://www.google.com/maps/place//data=!4m2!3m1!1s0x13355da6fb3e8f57:0xbb9c2e8f457892a0?sa=X&ved=2ahUKEwjk1sPi1c2DAxXsFhAIHRRUCIkQ4kB6BAgAEAA", "Description", 2, "slike", "Mare i ludaci sa skal", "123123", "https://www.google.hr" }
                });

            migrationBuilder.InsertData(
                table: "Users",
                columns: new[] { "Id", "Email", "FirstName", "Gender", "ImageUrl", "LastName", "Password", "PhoneNumber", "Role", "UserName" },
                values: new object[,]
                {
                    { 1, "mate@gmail.com", "mate", 1, "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTaH3HHWUg9doerWjizPgSdAa_mRfzNWtXQQR-MiADXfw&s", "matic", "123mate", "1234567890", 1, "mate123" },
                    { 2, "sime@gmail.com", "sime", 1, "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTaH3HHWUg9doerWjizPgSdAa_mRfzNWtXQQR-MiADXfw&s", "simic", "123mate", "1234567890", 1, "sime213" }
                });

            migrationBuilder.InsertData(
                table: "Schedules",
                columns: new[] { "Id", "Ends", "HairdresserId", "Starts" },
                values: new object[] { 1, new DateTime(2024, 1, 15, 16, 0, 0, 0, DateTimeKind.Unspecified), 1, new DateTime(2024, 1, 15, 8, 0, 0, 0, DateTimeKind.Unspecified) });

            migrationBuilder.InsertData(
                table: "Services",
                columns: new[] { "Id", "Description", "Duration", "Gender", "Name", "Price", "SalonId" },
                values: new object[] { 1, "Sisanje i pranje kose jako jako dobro i malo traceva", 10, 1, "Kratko sisanje", 10.199999999999999, 1 });

            migrationBuilder.InsertData(
                table: "WorkingHours",
                columns: new[] { "Id", "ClosingHour", "IsWorkingDay", "OpeningHour", "SalonId" },
                values: new object[,]
                {
                    { 1, new DateTime(2024, 1, 10, 14, 0, 0, 0, DateTimeKind.Unspecified), true, new DateTime(2024, 1, 10, 8, 0, 0, 0, DateTimeKind.Unspecified), 1 },
                    { 2, new DateTime(2024, 1, 10, 14, 0, 0, 0, DateTimeKind.Unspecified), true, new DateTime(2024, 1, 10, 8, 0, 0, 0, DateTimeKind.Unspecified), 2 },
                    { 3, new DateTime(2024, 1, 10, 14, 0, 0, 0, DateTimeKind.Unspecified), false, new DateTime(2024, 1, 10, 8, 0, 0, 0, DateTimeKind.Unspecified), 3 }
                });

            migrationBuilder.InsertData(
                table: "HairdresserServices",
                columns: new[] { "HairdresserId", "ServiceId" },
                values: new object[] { 1, 1 });

            migrationBuilder.InsertData(
                table: "Reservations",
                columns: new[] { "Id", "Ends", "Note", "Price", "ScheduleId", "ServiceId", "Starts", "UserId" },
                values: new object[,]
                {
                    { 1, new TimeOnly(10, 20, 0), "moze malo krace", 10.199999999999999, 1, 1, new TimeOnly(8, 0, 0), 1 },
                    { 2, new TimeOnly(10, 40, 0), "moze malo krace", 10.199999999999999, 1, 1, new TimeOnly(10, 20, 0), 1 }
                });

            migrationBuilder.InsertData(
                table: "ServiceMainServices",
                columns: new[] { "MainServiceId", "ServiceId" },
                values: new object[,]
                {
                    { 1, 1 },
                    { 2, 1 }
                });

            migrationBuilder.InsertData(
                table: "Reviews",
                columns: new[] { "Id", "Comment", "Date", "Rating", "ReservationId", "SalonId" },
                values: new object[,]
                {
                    { 1, "super trac", new DateTime(2024, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 4, 1, 1 },
                    { 2, "super trac 2", new DateTime(2024, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 5, 2, 1 }
                });

            migrationBuilder.CreateIndex(
                name: "IX_HairdresserServices_ServiceId",
                table: "HairdresserServices",
                column: "ServiceId");

            migrationBuilder.CreateIndex(
                name: "IX_Reservations_ScheduleId",
                table: "Reservations",
                column: "ScheduleId");

            migrationBuilder.CreateIndex(
                name: "IX_Reservations_ServiceId",
                table: "Reservations",
                column: "ServiceId");

            migrationBuilder.CreateIndex(
                name: "IX_Reservations_UserId",
                table: "Reservations",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Reviews_ReservationId",
                table: "Reviews",
                column: "ReservationId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Reviews_SalonId",
                table: "Reviews",
                column: "SalonId");

            migrationBuilder.CreateIndex(
                name: "IX_Schedules_HairdresserId",
                table: "Schedules",
                column: "HairdresserId");

            migrationBuilder.CreateIndex(
                name: "IX_ServiceMainServices_MainServiceId",
                table: "ServiceMainServices",
                column: "MainServiceId");

            migrationBuilder.CreateIndex(
                name: "IX_Services_SalonId",
                table: "Services",
                column: "SalonId");

            migrationBuilder.CreateIndex(
                name: "IX_WorkingHours_SalonId",
                table: "WorkingHours",
                column: "SalonId");
        }

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

            migrationBuilder.DropTable(
                name: "Reviews");

            migrationBuilder.DropTable(
                name: "ServiceMainServices");

            migrationBuilder.DropTable(
                name: "WorkingHours");

            migrationBuilder.DropTable(
                name: "Reservations");

            migrationBuilder.DropTable(
                name: "MainServices");

            migrationBuilder.DropTable(
                name: "Schedules");

            migrationBuilder.DropTable(
                name: "Services");

            migrationBuilder.DropTable(
                name: "Users");

            migrationBuilder.DropTable(
                name: "Hairdressers");

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