forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
254 lines
10 KiB
C#
254 lines
10 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace MagicCarpetDatabase.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class FirstMigration : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Clients",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<string>(type: "text", nullable: false),
|
|
FIO = table.Column<string>(type: "text", nullable: false),
|
|
PhoneNumber = table.Column<string>(type: "text", nullable: false),
|
|
DiscountSize = table.Column<double>(type: "double precision", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Clients", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Employees",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<string>(type: "text", nullable: false),
|
|
FIO = table.Column<string>(type: "text", nullable: false),
|
|
Email = table.Column<string>(type: "text", nullable: false),
|
|
PostId = table.Column<string>(type: "text", nullable: false),
|
|
BirthDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
EmploymentDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Employees", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Posts",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<string>(type: "text", nullable: false),
|
|
PostId = table.Column<string>(type: "text", nullable: false),
|
|
PostName = table.Column<string>(type: "text", nullable: false),
|
|
PostType = table.Column<int>(type: "integer", nullable: false),
|
|
Salary = table.Column<double>(type: "double precision", nullable: false),
|
|
IsActual = table.Column<bool>(type: "boolean", nullable: false),
|
|
ChangeDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Posts", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Tours",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<string>(type: "text", nullable: false),
|
|
TourName = table.Column<string>(type: "text", nullable: false),
|
|
TourCountry = table.Column<string>(type: "text", nullable: true),
|
|
Price = table.Column<double>(type: "double precision", nullable: false),
|
|
TourType = table.Column<int>(type: "integer", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Tours", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Salaries",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<string>(type: "text", nullable: false),
|
|
EmployeeId = table.Column<string>(type: "text", nullable: false),
|
|
SalaryDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
EmployeeSalary = table.Column<double>(type: "double precision", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Salaries", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Salaries_Employees_EmployeeId",
|
|
column: x => x.EmployeeId,
|
|
principalTable: "Employees",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Sales",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<string>(type: "text", nullable: false),
|
|
EmployeeId = table.Column<string>(type: "text", nullable: false),
|
|
ClientId = table.Column<string>(type: "text", nullable: true),
|
|
SaleDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
Sum = table.Column<double>(type: "double precision", nullable: false),
|
|
DiscountType = table.Column<int>(type: "integer", nullable: false),
|
|
Discount = table.Column<double>(type: "double precision", nullable: false),
|
|
IsCancel = table.Column<bool>(type: "boolean", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Sales", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Sales_Clients_ClientId",
|
|
column: x => x.ClientId,
|
|
principalTable: "Clients",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_Sales_Employees_EmployeeId",
|
|
column: x => x.EmployeeId,
|
|
principalTable: "Employees",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "TourHistories",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<string>(type: "text", nullable: false),
|
|
TourId = table.Column<string>(type: "text", nullable: false),
|
|
OldPrice = table.Column<double>(type: "double precision", nullable: false),
|
|
ChangeDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_TourHistories", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_TourHistories_Tours_TourId",
|
|
column: x => x.TourId,
|
|
principalTable: "Tours",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "SaleTours",
|
|
columns: table => new
|
|
{
|
|
SaleId = table.Column<string>(type: "text", nullable: false),
|
|
TourId = table.Column<string>(type: "text", nullable: false),
|
|
Count = table.Column<int>(type: "integer", nullable: false),
|
|
Price = table.Column<double>(type: "double precision", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_SaleTours", x => new { x.SaleId, x.TourId });
|
|
table.ForeignKey(
|
|
name: "FK_SaleTours_Sales_SaleId",
|
|
column: x => x.SaleId,
|
|
principalTable: "Sales",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_SaleTours_Tours_TourId",
|
|
column: x => x.TourId,
|
|
principalTable: "Tours",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Clients_PhoneNumber",
|
|
table: "Clients",
|
|
column: "PhoneNumber",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Posts_PostId_IsActual",
|
|
table: "Posts",
|
|
columns: new[] { "PostId", "IsActual" },
|
|
unique: true,
|
|
filter: "\"IsActual\" = TRUE");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Posts_PostName_IsActual",
|
|
table: "Posts",
|
|
columns: new[] { "PostName", "IsActual" },
|
|
unique: true,
|
|
filter: "\"IsActual\" = TRUE");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Salaries_EmployeeId",
|
|
table: "Salaries",
|
|
column: "EmployeeId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Sales_ClientId",
|
|
table: "Sales",
|
|
column: "ClientId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Sales_EmployeeId",
|
|
table: "Sales",
|
|
column: "EmployeeId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_SaleTours_TourId",
|
|
table: "SaleTours",
|
|
column: "TourId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_TourHistories_TourId",
|
|
table: "TourHistories",
|
|
column: "TourId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Tours_TourName",
|
|
table: "Tours",
|
|
column: "TourName",
|
|
unique: true);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Posts");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Salaries");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "SaleTours");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "TourHistories");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Sales");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Tours");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Clients");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Employees");
|
|
}
|
|
}
|
|
}
|