SUBD_Labs/BeautySalonDatabaseImplement/Migrations/20230516215849_InitialCreate.cs

167 lines
7.0 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace BeautySalonDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientFIO = table.Column<string>(type: "text", nullable: false),
PhoneNumber = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Masters",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
MasterFIO = table.Column<string>(type: "text", nullable: false),
Wage = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Masters", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Services",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ServiceName = table.Column<string>(type: "text", nullable: false),
Cost = table.Column<double>(type: "double precision", nullable: false),
Time = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Services", x => x.Id);
});
migrationBuilder.CreateTable(
name: "MasterServices",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
MasterId = table.Column<int>(type: "integer", nullable: false),
ServiceId = table.Column<int>(type: "integer", nullable: false),
Wage = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MasterServices", x => x.Id);
table.ForeignKey(
name: "FK_MasterServices_Masters_MasterId",
column: x => x.MasterId,
principalTable: "Masters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MasterServices_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Visits",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DateOfVisit = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: false),
ServiceId = table.Column<int>(type: "integer", nullable: false),
ClientFIO = table.Column<string>(type: "text", nullable: false),
ServiceName = table.Column<string>(type: "text", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
MasterId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Visits", x => x.Id);
table.ForeignKey(
name: "FK_Visits_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Visits_Masters_MasterId",
column: x => x.MasterId,
principalTable: "Masters",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Visits_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_MasterServices_MasterId",
table: "MasterServices",
column: "MasterId");
migrationBuilder.CreateIndex(
name: "IX_MasterServices_ServiceId",
table: "MasterServices",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_Visits_ClientId",
table: "Visits",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Visits_MasterId",
table: "Visits",
column: "MasterId");
migrationBuilder.CreateIndex(
name: "IX_Visits_ServiceId",
table: "Visits",
column: "ServiceId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "MasterServices");
migrationBuilder.DropTable(
name: "Visits");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Masters");
migrationBuilder.DropTable(
name: "Services");
}
}
}