using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace BankDatabaseImplement.Migrations
{
///
public partial class InitialCreate : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FirstName = table.Column(type: "text", nullable: false),
LastName = table.Column(type: "text", nullable: false),
MiddleName = table.Column(type: "text", nullable: true),
Address = table.Column(type: "text", nullable: false),
PhoneNumber = table.Column(type: "text", nullable: false),
Email = table.Column(type: "text", nullable: false),
Password = table.Column(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Employees",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FirstName = table.Column(type: "text", nullable: false),
LastName = table.Column(type: "text", nullable: false),
MiddleName = table.Column(type: "text", nullable: true),
Post = table.Column(type: "text", nullable: false),
PhoneNumber = table.Column(type: "text", nullable: false),
Password = table.Column(type: "text", nullable: false),
Email = table.Column(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Employees", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Purchases",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientId = table.Column(type: "integer", nullable: false),
DatePurchase = table.Column(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Purchases", x => x.Id);
table.ForeignKey(
name: "FK_Purchases_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Costs",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
EmployeeId = table.Column(type: "integer", nullable: false),
NameOfCost = table.Column(type: "text", nullable: false),
Price = table.Column(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Costs", x => x.Id);
table.ForeignKey(
name: "FK_Costs_Employees_EmployeeId",
column: x => x.EmployeeId,
principalTable: "Employees",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Operations",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
EmployeeId = table.Column(type: "integer", nullable: false),
Model = table.Column(type: "text", nullable: false),
Price = table.Column(type: "double precision", nullable: false),
Mark = table.Column(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Operations", x => x.Id);
table.ForeignKey(
name: "FK_Operations_Employees_EmployeeId",
column: x => x.EmployeeId,
principalTable: "Employees",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "CostByPurchases",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CostId = table.Column(type: "integer", nullable: false),
PurchaseId = table.Column(type: "integer", nullable: false),
Count = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CostByPurchases", x => x.Id);
table.ForeignKey(
name: "FK_CostByPurchases_Costs_CostId",
column: x => x.CostId,
principalTable: "Costs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CostByPurchases_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "OperationByPurchases",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OperationId = table.Column(type: "integer", nullable: false),
PurchaseId = table.Column(type: "integer", nullable: false),
CountOperations = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OperationByPurchases", x => x.Id);
table.ForeignKey(
name: "FK_OperationByPurchases_Operations_OperationId",
column: x => x.OperationId,
principalTable: "Operations",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_OperationByPurchases_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Payments",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OperationByPurchaseId = table.Column(type: "integer", nullable: false),
Date = table.Column(type: "date", nullable: false),
PaidPrice = table.Column(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Payments", x => x.Id);
table.ForeignKey(
name: "FK_Payments_OperationByPurchases_OperationByPurchaseId",
column: x => x.OperationByPurchaseId,
principalTable: "OperationByPurchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_CostByPurchases_CostId",
table: "CostByPurchases",
column: "CostId");
migrationBuilder.CreateIndex(
name: "IX_CostByPurchases_PurchaseId",
table: "CostByPurchases",
column: "PurchaseId");
migrationBuilder.CreateIndex(
name: "IX_Costs_EmployeeId",
table: "Costs",
column: "EmployeeId");
migrationBuilder.CreateIndex(
name: "IX_OperationByPurchases_OperationId",
table: "OperationByPurchases",
column: "OperationId");
migrationBuilder.CreateIndex(
name: "IX_OperationByPurchases_PurchaseId",
table: "OperationByPurchases",
column: "PurchaseId");
migrationBuilder.CreateIndex(
name: "IX_Operations_EmployeeId",
table: "Operations",
column: "EmployeeId");
migrationBuilder.CreateIndex(
name: "IX_Payments_OperationByPurchaseId",
table: "Payments",
column: "OperationByPurchaseId");
migrationBuilder.CreateIndex(
name: "IX_Purchases_ClientId",
table: "Purchases",
column: "ClientId");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CostByPurchases");
migrationBuilder.DropTable(
name: "Payments");
migrationBuilder.DropTable(
name: "Costs");
migrationBuilder.DropTable(
name: "OperationByPurchases");
migrationBuilder.DropTable(
name: "Operations");
migrationBuilder.DropTable(
name: "Purchases");
migrationBuilder.DropTable(
name: "Employees");
migrationBuilder.DropTable(
name: "Clients");
}
}
}