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), CabinetId = table.Column(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(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("PK_Kinds", x => x.Id); }); 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), StartDate = table.Column(type: "date", nullable: false), EndDate = table.Column(type: "date", nullable: true), DeviceId = table.Column(type: "int", nullable: false), ServiceId = table.Column(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(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), FullName = 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), AccessLevel = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Staff", 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), CabinetId = table.Column(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(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Model = table.Column(type: "nvarchar(max)", nullable: false), SerialNumber = table.Column(type: "nvarchar(max)", nullable: true), ProductionDate = table.Column(type: "date", nullable: true), WarrantyPeriod = table.Column(type: "int", nullable: true), Condition = table.Column(type: "bit", nullable: false), KindId = table.Column(type: "int", nullable: false), KitId = table.Column(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(type: "int", nullable: false), StaffId = table.Column(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"); } /// 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"); } } }