diff --git a/backend/api/Migrations/20230426114806_AddRobotModelTable.Designer.cs b/backend/api/Migrations/20230426114806_AddRobotModelTable.Designer.cs new file mode 100644 index 00000000..216be091 --- /dev/null +++ b/backend/api/Migrations/20230426114806_AddRobotModelTable.Designer.cs @@ -0,0 +1,671 @@ +// +using System; +using Api.Database.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Api.Migrations +{ + [DbContext(typeof(FlotillaDbContext))] + [Migration("20230426114806_AddRobotModelTable")] + partial class AddRobotModelTable + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("Api.Database.Models.AssetDeck", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AssetCode") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("DeckName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("AssetDecks"); + }); + + modelBuilder.Entity("Api.Database.Models.Mission", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AssetCode") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Comment") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Description") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("DesiredStartTime") + .HasColumnType("datetimeoffset"); + + b.Property("EchoMissionId") + .HasMaxLength(200) + .HasColumnType("int"); + + b.Property("EndTime") + .HasColumnType("datetimeoffset"); + + b.Property("EstimatedDuration") + .HasColumnType("time"); + + b.Property("IsarMissionId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("RobotId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("StartTime") + .HasColumnType("datetimeoffset"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("StatusReason") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RobotId"); + + b.ToTable("Missions"); + }); + + modelBuilder.Entity("Api.Database.Models.Robot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("BatteryLevel") + .HasColumnType("real"); + + b.Property("CurrentMissionId") + .HasColumnType("nvarchar(max)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("Host") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsarId") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ModelId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("PressureLevel") + .HasColumnType("real"); + + b.Property("SerialNumber") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ModelId"); + + b.ToTable("Robots"); + }); + + modelBuilder.Entity("Api.Database.Models.RobotModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("BatteryWarningThreshold") + .HasColumnType("real"); + + b.Property("LowerPressureWarningThreshold") + .HasColumnType("real"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(56)"); + + b.Property("UpperPressureWarningThreshold") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("Type") + .IsUnique(); + + b.ToTable("RobotModels"); + }); + + modelBuilder.Entity("Api.Database.Models.AssetDeck", b => + { + b.OwnsOne("Api.Database.Models.Pose", "DefaultLocalizationPose", b1 => + { + b1.Property("AssetDeckId") + .HasColumnType("nvarchar(450)"); + + b1.HasKey("AssetDeckId"); + + b1.ToTable("AssetDecks"); + + b1.WithOwner() + .HasForeignKey("AssetDeckId"); + + b1.OwnsOne("Api.Database.Models.Orientation", "Orientation", b2 => + { + b2.Property("PoseAssetDeckId") + .HasColumnType("nvarchar(450)"); + + b2.Property("W") + .HasColumnType("real"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseAssetDeckId"); + + b2.ToTable("AssetDecks"); + + b2.WithOwner() + .HasForeignKey("PoseAssetDeckId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "Position", b2 => + { + b2.Property("PoseAssetDeckId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseAssetDeckId"); + + b2.ToTable("AssetDecks"); + + b2.WithOwner() + .HasForeignKey("PoseAssetDeckId"); + }); + + b1.Navigation("Orientation") + .IsRequired(); + + b1.Navigation("Position") + .IsRequired(); + }); + + b.Navigation("DefaultLocalizationPose") + .IsRequired(); + }); + + modelBuilder.Entity("Api.Database.Models.Mission", b => + { + b.HasOne("Api.Database.Models.Robot", "Robot") + .WithMany() + .HasForeignKey("RobotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("Api.Database.Models.MissionMap", "Map", b1 => + { + b1.Property("MissionId") + .HasColumnType("nvarchar(450)"); + + b1.Property("MapName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.HasKey("MissionId"); + + b1.ToTable("Missions"); + + b1.WithOwner() + .HasForeignKey("MissionId"); + + b1.OwnsOne("Api.Database.Models.Boundary", "Boundary", b2 => + { + b2.Property("MissionMapMissionId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X1") + .HasColumnType("float"); + + b2.Property("X2") + .HasColumnType("float"); + + b2.Property("Y1") + .HasColumnType("float"); + + b2.Property("Y2") + .HasColumnType("float"); + + b2.Property("Z1") + .HasColumnType("float"); + + b2.Property("Z2") + .HasColumnType("float"); + + b2.HasKey("MissionMapMissionId"); + + b2.ToTable("Missions"); + + b2.WithOwner() + .HasForeignKey("MissionMapMissionId"); + }); + + b1.OwnsOne("Api.Database.Models.TransformationMatrices", "TransformationMatrices", b2 => + { + b2.Property("MissionMapMissionId") + .HasColumnType("nvarchar(450)"); + + b2.Property("C1") + .HasColumnType("float"); + + b2.Property("C2") + .HasColumnType("float"); + + b2.Property("D1") + .HasColumnType("float"); + + b2.Property("D2") + .HasColumnType("float"); + + b2.HasKey("MissionMapMissionId"); + + b2.ToTable("Missions"); + + b2.WithOwner() + .HasForeignKey("MissionMapMissionId"); + }); + + b1.Navigation("Boundary") + .IsRequired(); + + b1.Navigation("TransformationMatrices") + .IsRequired(); + }); + + b.OwnsMany("Api.Database.Models.MissionTask", "Tasks", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b1.Property("EchoPoseId") + .HasColumnType("int"); + + b1.Property("EchoTagLink") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.Property("EndTime") + .HasColumnType("datetimeoffset"); + + b1.Property("IsarTaskId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.Property("MissionId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b1.Property("StartTime") + .HasColumnType("datetimeoffset"); + + b1.Property("Status") + .HasColumnType("int"); + + b1.Property("TagId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.Property("TaskOrder") + .HasColumnType("int"); + + b1.HasKey("Id"); + + b1.HasIndex("MissionId"); + + b1.ToTable("MissionTask"); + + b1.WithOwner() + .HasForeignKey("MissionId"); + + b1.OwnsMany("Api.Database.Models.Inspection", "Inspections", b2 => + { + b2.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b2.Property("AnalysisTypes") + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b2.Property("EndTime") + .HasColumnType("datetimeoffset"); + + b2.Property("InspectionType") + .HasColumnType("int"); + + b2.Property("InspectionUrl") + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b2.Property("IsarStepId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b2.Property("MissionTaskId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b2.Property("StartTime") + .HasColumnType("datetimeoffset"); + + b2.Property("Status") + .HasColumnType("int"); + + b2.Property("VideoDuration") + .HasColumnType("real"); + + b2.HasKey("Id"); + + b2.HasIndex("MissionTaskId"); + + b2.ToTable("Inspection"); + + b2.WithOwner() + .HasForeignKey("MissionTaskId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "InspectionTarget", b2 => + { + b2.Property("MissionTaskId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("MissionTaskId"); + + b2.ToTable("MissionTask"); + + b2.WithOwner() + .HasForeignKey("MissionTaskId"); + }); + + b1.OwnsOne("Api.Database.Models.Pose", "RobotPose", b2 => + { + b2.Property("MissionTaskId") + .HasColumnType("nvarchar(450)"); + + b2.HasKey("MissionTaskId"); + + b2.ToTable("MissionTask"); + + b2.WithOwner() + .HasForeignKey("MissionTaskId"); + + b2.OwnsOne("Api.Database.Models.Orientation", "Orientation", b3 => + { + b3.Property("PoseMissionTaskId") + .HasColumnType("nvarchar(450)"); + + b3.Property("W") + .HasColumnType("real"); + + b3.Property("X") + .HasColumnType("real"); + + b3.Property("Y") + .HasColumnType("real"); + + b3.Property("Z") + .HasColumnType("real"); + + b3.HasKey("PoseMissionTaskId"); + + b3.ToTable("MissionTask"); + + b3.WithOwner() + .HasForeignKey("PoseMissionTaskId"); + }); + + b2.OwnsOne("Api.Database.Models.Position", "Position", b3 => + { + b3.Property("PoseMissionTaskId") + .HasColumnType("nvarchar(450)"); + + b3.Property("X") + .HasColumnType("real"); + + b3.Property("Y") + .HasColumnType("real"); + + b3.Property("Z") + .HasColumnType("real"); + + b3.HasKey("PoseMissionTaskId"); + + b3.ToTable("MissionTask"); + + b3.WithOwner() + .HasForeignKey("PoseMissionTaskId"); + }); + + b2.Navigation("Orientation") + .IsRequired(); + + b2.Navigation("Position") + .IsRequired(); + }); + + b1.Navigation("InspectionTarget") + .IsRequired(); + + b1.Navigation("Inspections"); + + b1.Navigation("RobotPose") + .IsRequired(); + }); + + b.Navigation("Map"); + + b.Navigation("Robot"); + + b.Navigation("Tasks"); + }); + + modelBuilder.Entity("Api.Database.Models.Robot", b => + { + b.HasOne("Api.Database.Models.RobotModel", "Model") + .WithMany() + .HasForeignKey("ModelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("Api.Database.Models.Pose", "Pose", b1 => + { + b1.Property("RobotId") + .HasColumnType("nvarchar(450)"); + + b1.HasKey("RobotId"); + + b1.ToTable("Robots"); + + b1.WithOwner() + .HasForeignKey("RobotId"); + + b1.OwnsOne("Api.Database.Models.Orientation", "Orientation", b2 => + { + b2.Property("PoseRobotId") + .HasColumnType("nvarchar(450)"); + + b2.Property("W") + .HasColumnType("real"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseRobotId"); + + b2.ToTable("Robots"); + + b2.WithOwner() + .HasForeignKey("PoseRobotId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "Position", b2 => + { + b2.Property("PoseRobotId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseRobotId"); + + b2.ToTable("Robots"); + + b2.WithOwner() + .HasForeignKey("PoseRobotId"); + }); + + b1.Navigation("Orientation") + .IsRequired(); + + b1.Navigation("Position") + .IsRequired(); + }); + + b.OwnsMany("Api.Database.Models.VideoStream", "VideoStreams", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.Property("RobotId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b1.Property("ShouldRotate270Clockwise") + .HasColumnType("bit"); + + b1.Property("Type") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b1.Property("Url") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.HasKey("Id"); + + b1.HasIndex("RobotId"); + + b1.ToTable("VideoStream"); + + b1.WithOwner() + .HasForeignKey("RobotId"); + }); + + b.Navigation("Model"); + + b.Navigation("Pose") + .IsRequired(); + + b.Navigation("VideoStreams"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/api/Migrations/20230426114806_AddRobotModelTable.cs b/backend/api/Migrations/20230426114806_AddRobotModelTable.cs new file mode 100644 index 00000000..0f66bf3c --- /dev/null +++ b/backend/api/Migrations/20230426114806_AddRobotModelTable.cs @@ -0,0 +1,86 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Api.Migrations +{ + public partial class AddRobotModelTable : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn(name: "Model", table: "Robots"); + + migrationBuilder.AddColumn( + name: "ModelId", + table: "Robots", + type: "nvarchar(450)", + nullable: true, + defaultValue: "" + ); + + migrationBuilder.CreateTable( + name: "RobotModels", + columns: table => + new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Type = table.Column(type: "nvarchar(56)", nullable: false), + BatteryWarningThreshold = table.Column(type: "real", nullable: true), + UpperPressureWarningThreshold = table.Column( + type: "real", + nullable: true + ), + LowerPressureWarningThreshold = table.Column( + type: "real", + nullable: true + ) + }, + constraints: table => + { + table.PrimaryKey("PK_RobotModels", x => x.Id); + } + ); + + migrationBuilder.CreateIndex( + name: "IX_Robots_ModelId", + table: "Robots", + column: "ModelId" + ); + + migrationBuilder.CreateIndex( + name: "IX_RobotModels_Type", + table: "RobotModels", + column: "Type", + unique: true + ); + + migrationBuilder.AddForeignKey( + name: "FK_Robots_RobotModels_ModelId", + table: "Robots", + column: "ModelId", + principalTable: "RobotModels", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade + ); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey(name: "FK_Robots_RobotModels_ModelId", table: "Robots"); + + migrationBuilder.DropTable(name: "RobotModels"); + + migrationBuilder.DropIndex(name: "IX_Robots_ModelId", table: "Robots"); + + migrationBuilder.DropColumn(name: "ModelId", table: "Robots"); + + migrationBuilder.AddColumn( + name: "Model", + table: "Robots", + type: "int", + nullable: false, + defaultValue: 0 + ); + } + } +} diff --git a/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs b/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs index 21a10875..2636b9b7 100644 --- a/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs +++ b/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs @@ -130,8 +130,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(200) .HasColumnType("nvarchar(200)"); - b.Property("Model") - .HasColumnType("int"); + b.Property("ModelId") + .IsRequired() + .HasColumnType("nvarchar(450)"); b.Property("Name") .IsRequired() @@ -154,9 +155,38 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("ModelId"); + b.ToTable("Robots"); }); + modelBuilder.Entity("Api.Database.Models.RobotModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("BatteryWarningThreshold") + .HasColumnType("real"); + + b.Property("LowerPressureWarningThreshold") + .HasColumnType("real"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(56)"); + + b.Property("UpperPressureWarningThreshold") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("Type") + .IsUnique(); + + b.ToTable("RobotModels"); + }); + modelBuilder.Entity("Api.Database.Models.AssetDeck", b => { b.OwnsOne("Api.Database.Models.Pose", "DefaultLocalizationPose", b1 => @@ -516,6 +546,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Api.Database.Models.Robot", b => { + b.HasOne("Api.Database.Models.RobotModel", "Model") + .WithMany() + .HasForeignKey("ModelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.OwnsOne("Api.Database.Models.Pose", "Pose", b1 => { b1.Property("RobotId") @@ -620,6 +656,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasForeignKey("RobotId"); }); + b.Navigation("Model"); + b.Navigation("Pose") .IsRequired();