216 lines
8.7 KiB
C#
216 lines
8.7 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace LawFirmDatabase.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialCreate : 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: "Cases",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
DateCreated = table.Column<DateTime>(type: "date", nullable: false),
|
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
CustomerId = table.Column<int>(type: "int", nullable: false),
|
|
CaseId = table.Column<int>(type: "int", nullable: false),
|
|
WorkerId = table.Column<int>(type: "int", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Cases", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Cases_Customers_CaseId",
|
|
column: x => x.CaseId,
|
|
principalTable: "Customers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Cases_Workers_WorkerId",
|
|
column: x => x.WorkerId,
|
|
principalTable: "Workers",
|
|
principalColumn: "Id");
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "CaseServices",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
CaseId = table.Column<int>(type: "int", nullable: false),
|
|
ServiceId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_CaseServices", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_CaseServices_Cases_CaseId",
|
|
column: x => x.CaseId,
|
|
principalTable: "Cases",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Payments",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
DatePayment = table.Column<DateTime>(type: "date", nullable: false),
|
|
Sum = table.Column<decimal>(type: "decimal (15,2)", nullable: false),
|
|
CaseId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Payments", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Payments_Cases_CaseId",
|
|
column: x => x.CaseId,
|
|
principalTable: "Cases",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Services",
|
|
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 (15,2)", nullable: false),
|
|
ItemId = table.Column<int>(type: "int", nullable: false),
|
|
CaseId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Services", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Services_Cases_CaseId",
|
|
column: x => x.CaseId,
|
|
principalTable: "Cases",
|
|
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),
|
|
PaymentId = table.Column<int>(type: "int", nullable: false),
|
|
ItemId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Items", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Items_Payments_ItemId",
|
|
column: x => x.ItemId,
|
|
principalTable: "Payments",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Cases_CaseId",
|
|
table: "Cases",
|
|
column: "CaseId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Cases_WorkerId",
|
|
table: "Cases",
|
|
column: "WorkerId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_CaseServices_CaseId",
|
|
table: "CaseServices",
|
|
column: "CaseId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Items_ItemId",
|
|
table: "Items",
|
|
column: "ItemId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Payments_CaseId",
|
|
table: "Payments",
|
|
column: "CaseId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Services_CaseId",
|
|
table: "Services",
|
|
column: "CaseId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "CaseServices");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Items");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Services");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Payments");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Cases");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Customers");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Workers");
|
|
}
|
|
}
|
|
}
|