286 lines
12 KiB
C#
286 lines
12 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace CarServiceDatabase.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitMigration : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Customers",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Surname = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Customers", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Workers",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Surname = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Workers", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Vehicles",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Plate = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
VIN = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
CustomerId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Vehicles", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Vehicles_Customers_CustomerId",
|
|
column: x => x.CustomerId,
|
|
principalTable: "Customers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Items",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Price = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
|
Count = table.Column<int>(type: "int", nullable: false),
|
|
WorkerId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Items", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Items_Workers_WorkerId",
|
|
column: x => x.WorkerId,
|
|
principalTable: "Workers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Works",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Price = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
|
Duration = table.Column<decimal>(type: "decimal (3,1)", nullable: false),
|
|
WorkerId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Works", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Works_Workers_WorkerId",
|
|
column: x => x.WorkerId,
|
|
principalTable: "Workers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "RepairRequests",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
DateCreated = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
VehicleId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_RepairRequests", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_RepairRequests_Vehicles_VehicleId",
|
|
column: x => x.VehicleId,
|
|
principalTable: "Vehicles",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "ItemsForRepair",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Count = table.Column<int>(type: "int", nullable: false),
|
|
ItemId = table.Column<int>(type: "int", nullable: false),
|
|
RepairRequestId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_ItemsForRepair", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_ItemsForRepair_Items_ItemId",
|
|
column: x => x.ItemId,
|
|
principalTable: "Items",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_ItemsForRepair_RepairRequests_RepairRequestId",
|
|
column: x => x.RepairRequestId,
|
|
principalTable: "RepairRequests",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "WorksInRequest",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Count = table.Column<int>(type: "int", nullable: false),
|
|
Cost = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
|
RepairRequestId = table.Column<int>(type: "int", nullable: false),
|
|
WorkId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_WorksInRequest", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_WorksInRequest_RepairRequests_RepairRequestId",
|
|
column: x => x.RepairRequestId,
|
|
principalTable: "RepairRequests",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_WorksInRequest_Works_WorkId",
|
|
column: x => x.WorkId,
|
|
principalTable: "Works",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "WorkPayments",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
DatePayment = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
Sum = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
|
WorkInRequestId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_WorkPayments", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_WorkPayments_WorksInRequest_WorkInRequestId",
|
|
column: x => x.WorkInRequestId,
|
|
principalTable: "WorksInRequest",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Items_WorkerId",
|
|
table: "Items",
|
|
column: "WorkerId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_ItemsForRepair_ItemId",
|
|
table: "ItemsForRepair",
|
|
column: "ItemId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_ItemsForRepair_RepairRequestId",
|
|
table: "ItemsForRepair",
|
|
column: "RepairRequestId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_RepairRequests_VehicleId",
|
|
table: "RepairRequests",
|
|
column: "VehicleId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Vehicles_CustomerId",
|
|
table: "Vehicles",
|
|
column: "CustomerId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_WorkPayments_WorkInRequestId",
|
|
table: "WorkPayments",
|
|
column: "WorkInRequestId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Works_WorkerId",
|
|
table: "Works",
|
|
column: "WorkerId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_WorksInRequest_RepairRequestId",
|
|
table: "WorksInRequest",
|
|
column: "RepairRequestId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_WorksInRequest_WorkId",
|
|
table: "WorksInRequest",
|
|
column: "WorkId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "ItemsForRepair");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "WorkPayments");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Items");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "WorksInRequest");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "RepairRequests");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Works");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Vehicles");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Workers");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Customers");
|
|
}
|
|
}
|
|
}
|