using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace DeviceDatabaseImplement.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Cabinets", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Room = table.Column(type: "nvarchar(max)", nullable: false), Building = table.Column(type: "int", nullable: false), }, constraints: table => { table.PrimaryKey("Cabinets_PKey", x => x.Id); }); migrationBuilder.CreateTable( name: "Kits", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Title = table.Column(type: "nvarchar(max)", nullable: false), Cabinet_Id = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("Kits_PKey", x => x.Id); table.ForeignKey( name: "Kits_Cabinet_Id_FKey", column: x => x.Cabinet_Id, principalTable: "Cabinets", principalColumn: "Id", onDelete: ReferentialAction.SetNull, onUpdate: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Kinds", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Title = table.Column(type: "nvarchar(max)", nullable: false), Frequency = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("Kinds_PKey", x => x.Id); }); migrationBuilder.CreateTable( name: "Devices", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Model = table.Column(type: "nvarchar(max)", nullable: false), Serial_Number = table.Column(type: "nvarchar(max)", nullable: true), Production_Date = table.Column(type: "date", nullable: true), Warranty_Period = table.Column(type: "int", nullable: true), Condition = table.Column(type: "bit", nullable: false), Kind_Id = table.Column(type: "int", nullable: false), Kit_Id = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("Devices_Pkey", x => x.Id); table.ForeignKey( name: "Devices_Kind_Id_FKey", column: x => x.Kind_Id, principalTable: "Kinds", principalColumn: "Id", onDelete: ReferentialAction.Restrict, onUpdate: ReferentialAction.Cascade); table.ForeignKey( name: "Devices_Kit_Id_FKey", column: x => x.Kit_Id, principalTable: "Kits", principalColumn: "Id", onDelete: ReferentialAction.SetNull, onUpdate: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Services", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Description = table.Column(type: "nvarchar(max)", nullable: false), Start_Date = table.Column(type: "date", nullable: false), End_Date = table.Column(type: "date", nullable: true), Device_Id = table.Column(type: "int", nullable: false), }, constraints: table => { table.PrimaryKey("Services_PKey", x => x.Id); table.ForeignKey( name: "Services_Device_Id_FKey", column: x => x.Device_Id, principalTable: "Devices", principalColumn: "Id", onDelete: ReferentialAction.Cascade, onUpdate: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Staff", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Full_Name = table.Column(type: "nvarchar(max)", nullable: false), Department = table.Column(type: "nvarchar(max)", nullable: false), Email = table.Column(type: "nvarchar(max)", nullable: false), Password = table.Column(type: "nvarchar(max)", nullable: false), Access_Level = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("Staff_PKey", x => x.Id); }); migrationBuilder.CreateTable( name: "Ownership", columns: table => new { Kit_Id = table.Column(type: "int", nullable: false), Staff_Id = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Ownership", x => new { x.Staff_Id, x.Kit_Id }); table.ForeignKey( name: "Ownership_Kit_Id_FKey", column: x => x.Kit_Id, principalTable: "Kits", principalColumn: "Id", onDelete: ReferentialAction.Cascade, onUpdate: ReferentialAction.Cascade); table.ForeignKey( name: "Ownership_Staff_Id_FKey", column: x => x.Staff_Id, principalTable: "Staff", principalColumn: "Id", onDelete: ReferentialAction.Cascade, onUpdate: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Devices_Kind_Id", table: "Devices", column: "Kind_Id"); migrationBuilder.CreateIndex( name: "IX_Devices_Kit_Id", table: "Devices", column: "Kit_Id"); migrationBuilder.CreateIndex( name: "IX_Kits_Cabinet_Id", table: "Kits", column: "Cabinet_Id"); migrationBuilder.CreateIndex( name: "IX_Ownership_Kit_Id", table: "Ownership", column: "Kit_Id"); migrationBuilder.CreateIndex( name: "IX_Ownership_Staff_Id", table: "Ownership", column: "Staff_Id"); migrationBuilder.CreateIndex( name: "IX_Services_Device_Id", table: "Services", column: "Device_Id"); } /// 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"); } } }