217 lines
8.7 KiB
C#
217 lines
8.7 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace DeviceDatabaseImplement.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialCreate : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Cabinets",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Room = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Building = table.Column<int>(type: "int", nullable: false),
|
|
CabinetId = table.Column<int>(type: "int", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Cabinets", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Cabinets_Cabinets_CabinetId",
|
|
column: x => x.CabinetId,
|
|
principalTable: "Cabinets",
|
|
principalColumn: "Id");
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Kinds",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Frequency = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Kinds", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Services",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
StartDate = table.Column<DateOnly>(type: "date", nullable: false),
|
|
EndDate = table.Column<DateOnly>(type: "date", nullable: true),
|
|
DeviceId = table.Column<int>(type: "int", nullable: false),
|
|
ServiceId = table.Column<int>(type: "int", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Services", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Services_Services_ServiceId",
|
|
column: x => x.ServiceId,
|
|
principalTable: "Services",
|
|
principalColumn: "Id");
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Staff",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
FullName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Department = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
AccessLevel = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Staff", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Kits",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
CabinetId = table.Column<int>(type: "int", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Kits", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Kits_Cabinets_CabinetId",
|
|
column: x => x.CabinetId,
|
|
principalTable: "Cabinets",
|
|
principalColumn: "Id");
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Devices",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Model = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
SerialNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
ProductionDate = table.Column<DateOnly>(type: "date", nullable: true),
|
|
WarrantyPeriod = table.Column<int>(type: "int", nullable: true),
|
|
Condition = table.Column<bool>(type: "bit", nullable: false),
|
|
KindId = table.Column<int>(type: "int", nullable: false),
|
|
KitId = table.Column<int>(type: "int", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Devices", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Devices_Kinds_KindId",
|
|
column: x => x.KindId,
|
|
principalTable: "Kinds",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Devices_Kits_KitId",
|
|
column: x => x.KitId,
|
|
principalTable: "Kits",
|
|
principalColumn: "Id");
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Ownership",
|
|
columns: table => new
|
|
{
|
|
KitId = table.Column<int>(type: "int", nullable: false),
|
|
StaffId = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Ownership", x => new { x.StaffId, x.KitId });
|
|
table.ForeignKey(
|
|
name: "FK_Ownership_Kits_KitId",
|
|
column: x => x.KitId,
|
|
principalTable: "Kits",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Ownership_Staff_StaffId",
|
|
column: x => x.StaffId,
|
|
principalTable: "Staff",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Cabinets_CabinetId",
|
|
table: "Cabinets",
|
|
column: "CabinetId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Devices_KindId",
|
|
table: "Devices",
|
|
column: "KindId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Devices_KitId",
|
|
table: "Devices",
|
|
column: "KitId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Kits_CabinetId",
|
|
table: "Kits",
|
|
column: "CabinetId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Ownership_KitId",
|
|
table: "Ownership",
|
|
column: "KitId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Services_ServiceId",
|
|
table: "Services",
|
|
column: "ServiceId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Devices");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Ownership");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Services");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Kinds");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Kits");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Staff");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Cabinets");
|
|
}
|
|
}
|
|
}
|