diff --git a/backend/api/Controllers/AreaController.cs b/backend/api/Controllers/AreaController.cs index 195052fde..77336208f 100644 --- a/backend/api/Controllers/AreaController.cs +++ b/backend/api/Controllers/AreaController.cs @@ -272,7 +272,7 @@ public async Task> GetMapMetadata([FromRoute] string i }; try { - mapMetadata = await _mapService.ChooseMapFromPositions(positions, area.Deck.Plant.Installation.InstallationCode); + mapMetadata = await _mapService.ChooseMapFromPositions(positions, area.Installation.InstallationCode); } catch (RequestFailedException e) { diff --git a/backend/api/Database/Context/FlotillaDbContext.cs b/backend/api/Database/Context/FlotillaDbContext.cs index d6c958f0b..145c0ea0c 100644 --- a/backend/api/Database/Context/FlotillaDbContext.cs +++ b/backend/api/Database/Context/FlotillaDbContext.cs @@ -57,14 +57,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) ); } ); - //missionRunEntity.HasOne(missionRun => missionRun.MissionDefinition); } ); - modelBuilder.Entity().HasOne(m => m.Source); modelBuilder.Entity().OwnsOne(m => m.MapMetadata).OwnsOne(t => t.TransformationMatrices); modelBuilder.Entity().OwnsOne(m => m.MapMetadata).OwnsOne(b => b.Boundary); - //modelBuilder.Entity().HasOne(m => m.LastRun).WithOne(m => m.MissionDefinition).HasForeignKey(m => m.Id); modelBuilder.Entity().OwnsOne(r => r.Pose).OwnsOne(p => p.Orientation); modelBuilder.Entity().OwnsOne(r => r.Pose).OwnsOne(p => p.Position); modelBuilder.Entity().OwnsMany(r => r.VideoStreams); @@ -73,12 +70,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) poseBuilder.OwnsOne(pose => pose.Position); poseBuilder.OwnsOne(pose => pose.Orientation); }); - modelBuilder.Entity().HasOne(a => a.Deck); - modelBuilder.Entity().HasOne(a => a.Installation); - modelBuilder.Entity().HasOne(a => a.Plant); - modelBuilder.Entity().HasOne(d => d.Plant); - modelBuilder.Entity().HasOne(d => d.Installation); - modelBuilder.Entity().HasOne(a => a.Installation); + modelBuilder.Entity().HasOne(a => a.Deck).WithMany(); + modelBuilder.Entity().HasOne(a => a.Installation).WithMany(); + modelBuilder.Entity().HasOne(a => a.Plant).WithMany(); + modelBuilder.Entity().HasOne(d => d.Plant).WithMany(); + modelBuilder.Entity().HasOne(d => d.Installation).WithMany(); + modelBuilder.Entity().HasOne(a => a.Installation).WithMany(); modelBuilder.Entity().OwnsOne(s => s.Pose, poseBuilder => { @@ -92,6 +89,22 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) // There can only be one unique installation and plant shortname modelBuilder.Entity().HasIndex(a => new { a.InstallationCode }).IsUnique(); modelBuilder.Entity().HasIndex(a => new { a.PlantCode }).IsUnique(); + + modelBuilder.Entity().HasOne(a => a.Deck).WithMany().OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity().HasOne(a => a.Plant).WithMany().OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity().HasOne(a => a.Installation).WithMany().OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity().HasOne(d => d.Plant).WithMany().OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity().HasOne(d => d.Installation).WithMany().OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity().HasOne(p => p.Installation).WithMany().OnDelete(DeleteBehavior.Restrict); + + foreach (var entityType in modelBuilder.Model.GetEntityTypes()) + { + entityType.SetTableName(entityType.DisplayName()); + entityType.GetForeignKeys() + .Where(fk => !fk.IsOwnership && fk.DeleteBehavior == DeleteBehavior.Cascade) + .ToList() + .ForEach(fk => fk.DeleteBehavior = DeleteBehavior.Restrict); + } } // SQLite does not have proper support for DateTimeOffset via Entity Framework Core, see the limitations diff --git a/backend/api/Database/Context/InitDb.cs b/backend/api/Database/Context/InitDb.cs index 4a944b66e..04c882105 100644 --- a/backend/api/Database/Context/InitDb.cs +++ b/backend/api/Database/Context/InitDb.cs @@ -183,7 +183,7 @@ private static List GetMissionDefinitions() { Id = Guid.NewGuid().ToString(), Name = "Placeholder Mission 1", - InstallationCode = areas[0].Deck.Plant.Installation.InstallationCode, + InstallationCode = areas[0].Installation.InstallationCode, Area = areas[0], Source = sources[0], Comment = "Interesting comment", @@ -195,7 +195,7 @@ private static List GetMissionDefinitions() { Id = Guid.NewGuid().ToString(), Name = "Placeholder Mission 2", - InstallationCode = areas[1].Deck.Plant.Installation.InstallationCode, + InstallationCode = areas[1].Installation.InstallationCode, Area = areas[1], Source = sources[1], InspectionFrequency = new DateTime().AddDays(7) - new DateTime(), @@ -206,7 +206,7 @@ private static List GetMissionDefinitions() { Id = Guid.NewGuid().ToString(), Name = "Placeholder Mission 3", - InstallationCode = areas[1].Deck.Plant.Installation.InstallationCode, + InstallationCode = areas[1].Installation.InstallationCode, Area = areas[1], Source = sources[1], LastRun = null @@ -221,7 +221,7 @@ private static List GetMissionRuns() { Name = "Placeholder Mission 1", Robot = robots[0], - InstallationCode = areas[0].Deck.Plant.Installation.InstallationCode, + InstallationCode = areas[0].Installation.InstallationCode, Area = areas[0], MissionId = missionDefinitions[0].Id, Status = MissionStatus.Successful, @@ -234,7 +234,7 @@ private static List GetMissionRuns() { Name = "Placeholder Mission 2", Robot = robots[1], - InstallationCode = areas[1].Deck.Plant.Installation.InstallationCode, + InstallationCode = areas[1].Installation.InstallationCode, Area = areas[1], MissionId = missionDefinitions[0].Id, Status = MissionStatus.Successful, @@ -248,7 +248,7 @@ private static List GetMissionRuns() { Name = "Placeholder Mission 3", Robot = robots[2], - InstallationCode = areas[1].Deck.Plant.Installation.InstallationCode, + InstallationCode = areas[1].Installation.InstallationCode, Area = areas[1], MissionId = missionDefinitions[1].Id, Status = MissionStatus.Successful, diff --git a/backend/api/Database/Models/Deck.cs b/backend/api/Database/Models/Deck.cs index cd7508aa5..6411ab3ed 100644 --- a/backend/api/Database/Models/Deck.cs +++ b/backend/api/Database/Models/Deck.cs @@ -10,11 +10,9 @@ public class Deck [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public string Id { get; set; } - [Required] - public virtual Plant Plant { get; set; } + public virtual Plant? Plant { get; set; } - [Required] - public virtual Installation Installation { get; set; } + public virtual Installation? Installation { get; set; } [Required] [MaxLength(200)] diff --git a/backend/api/Database/Models/Plant.cs b/backend/api/Database/Models/Plant.cs index 7a7141bb3..9873b61ff 100644 --- a/backend/api/Database/Models/Plant.cs +++ b/backend/api/Database/Models/Plant.cs @@ -10,8 +10,7 @@ public class Plant [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public string Id { get; set; } - [Required] - public virtual Installation Installation { get; set; } + public virtual Installation? Installation { get; set; } [Required] [MaxLength(10)] diff --git a/backend/api/Migrations/20230727084402_MissionRunAndAreaRefactor.Designer.cs b/backend/api/Migrations/20230727084402_MissionRunAndAreaRefactor.Designer.cs new file mode 100644 index 000000000..839701688 --- /dev/null +++ b/backend/api/Migrations/20230727084402_MissionRunAndAreaRefactor.Designer.cs @@ -0,0 +1,1135 @@ +// +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("20230727084402_MissionRunAndAreaRefactor")] + partial class MissionRunAndAreaRefactor + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Api.Database.Models.Area", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("DeckId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("DeckId"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantId"); + + b.ToTable("Area"); + }); + + 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("AssetDeck"); + }); + + modelBuilder.Entity("Api.Database.Models.Deck", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantId"); + + b.ToTable("Deck"); + }); + + modelBuilder.Entity("Api.Database.Models.Installation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationCode") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationCode") + .IsUnique(); + + b.ToTable("Installation"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("Comment") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("InspectionFrequency") + .HasColumnType("time"); + + b.Property("InstallationCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeprecated") + .HasColumnType("bit"); + + b.Property("LastRunId") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("AreaId"); + + b.HasIndex("LastRunId"); + + b.HasIndex("SourceId"); + + b.ToTable("MissionDefinition"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionRun", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("Comment") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Description") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("DesiredStartTime") + .HasColumnType("datetimeoffset"); + + b.Property("EndTime") + .HasColumnType("datetimeoffset"); + + b.Property("EstimatedDuration") + .HasColumnType("bigint"); + + b.Property("InstallationCode") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsarMissionId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("MissionId") + .HasColumnType("nvarchar(max)"); + + 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("AreaId"); + + b.HasIndex("RobotId"); + + b.ToTable("MissionRun"); + }); + + modelBuilder.Entity("Api.Database.Models.Plant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantCode") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantCode") + .IsUnique(); + + b.ToTable("Plant"); + }); + + modelBuilder.Entity("Api.Database.Models.Robot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("BatteryLevel") + .HasColumnType("real"); + + b.Property("CurrentAreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("CurrentInstallation") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + 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("CurrentAreaId"); + + b.HasIndex("ModelId"); + + b.ToTable("Robot"); + }); + + modelBuilder.Entity("Api.Database.Models.RobotModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AverageDurationPerTag") + .HasColumnType("real"); + + 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("RobotModel"); + }); + + modelBuilder.Entity("Api.Database.Models.SafePosition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("AreaId"); + + b.ToTable("SafePosition"); + }); + + modelBuilder.Entity("Api.Database.Models.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Source"); + }); + + modelBuilder.Entity("Api.Database.Models.Area", b => + { + b.HasOne("Api.Database.Models.Deck", "Deck") + .WithMany() + .HasForeignKey("DeckId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Api.Database.Models.Plant", "Plant") + .WithMany() + .HasForeignKey("PlantId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.OwnsOne("Api.Database.Models.Pose", "DefaultLocalizationPose", b1 => + { + b1.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b1.HasKey("AreaId"); + + b1.ToTable("Area.DefaultLocalizationPose#Pose"); + + b1.WithOwner() + .HasForeignKey("AreaId"); + + b1.OwnsOne("Api.Database.Models.Orientation", "Orientation", b2 => + { + b2.Property("PoseAreaId") + .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("PoseAreaId"); + + b2.ToTable("Area.DefaultLocalizationPose#Pose.Orientation#Orientation"); + + b2.WithOwner() + .HasForeignKey("PoseAreaId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "Position", b2 => + { + b2.Property("PoseAreaId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseAreaId"); + + b2.ToTable("Area.DefaultLocalizationPose#Pose.Position#Position"); + + b2.WithOwner() + .HasForeignKey("PoseAreaId"); + }); + + b1.Navigation("Orientation") + .IsRequired(); + + b1.Navigation("Position") + .IsRequired(); + }); + + b.OwnsOne("Api.Database.Models.MapMetadata", "MapMetadata", b1 => + { + b1.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b1.Property("MapName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.HasKey("AreaId"); + + b1.ToTable("Area.MapMetadata#MapMetadata"); + + b1.WithOwner() + .HasForeignKey("AreaId"); + + b1.OwnsOne("Api.Database.Models.Boundary", "Boundary", b2 => + { + b2.Property("MapMetadataAreaId") + .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("MapMetadataAreaId"); + + b2.ToTable("Area.MapMetadata#MapMetadata.Boundary#Boundary"); + + b2.WithOwner() + .HasForeignKey("MapMetadataAreaId"); + }); + + b1.OwnsOne("Api.Database.Models.TransformationMatrices", "TransformationMatrices", b2 => + { + b2.Property("MapMetadataAreaId") + .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("MapMetadataAreaId"); + + b2.ToTable("Area.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices"); + + b2.WithOwner() + .HasForeignKey("MapMetadataAreaId"); + }); + + b1.Navigation("Boundary") + .IsRequired(); + + b1.Navigation("TransformationMatrices") + .IsRequired(); + }); + + b.Navigation("Deck"); + + b.Navigation("DefaultLocalizationPose") + .IsRequired(); + + b.Navigation("Installation"); + + b.Navigation("MapMetadata") + .IsRequired(); + + b.Navigation("Plant"); + }); + + modelBuilder.Entity("Api.Database.Models.Deck", b => + { + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Api.Database.Models.Plant", "Plant") + .WithMany() + .HasForeignKey("PlantId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Installation"); + + b.Navigation("Plant"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionDefinition", b => + { + b.HasOne("Api.Database.Models.Area", "Area") + .WithMany() + .HasForeignKey("AreaId"); + + b.HasOne("Api.Database.Models.MissionRun", "LastRun") + .WithMany() + .HasForeignKey("LastRunId"); + + b.HasOne("Api.Database.Models.Source", "Source") + .WithMany() + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Area"); + + b.Navigation("LastRun"); + + b.Navigation("Source"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionRun", b => + { + b.HasOne("Api.Database.Models.Area", "Area") + .WithMany() + .HasForeignKey("AreaId"); + + b.HasOne("Api.Database.Models.Robot", "Robot") + .WithMany() + .HasForeignKey("RobotId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.OwnsOne("Api.Database.Models.MapMetadata", "MapMetadata", b1 => + { + b1.Property("MissionRunId") + .HasColumnType("nvarchar(450)"); + + b1.Property("MapName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.HasKey("MissionRunId"); + + b1.ToTable("MissionRun.MapMetadata#MapMetadata"); + + b1.WithOwner() + .HasForeignKey("MissionRunId"); + + b1.OwnsOne("Api.Database.Models.Boundary", "Boundary", b2 => + { + b2.Property("MapMetadataMissionRunId") + .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("MapMetadataMissionRunId"); + + b2.ToTable("MissionRun.MapMetadata#MapMetadata.Boundary#Boundary"); + + b2.WithOwner() + .HasForeignKey("MapMetadataMissionRunId"); + }); + + b1.OwnsOne("Api.Database.Models.TransformationMatrices", "TransformationMatrices", b2 => + { + b2.Property("MapMetadataMissionRunId") + .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("MapMetadataMissionRunId"); + + b2.ToTable("MissionRun.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices"); + + b2.WithOwner() + .HasForeignKey("MapMetadataMissionRunId"); + }); + + 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("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + 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("MissionRunId") + .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("MissionRunId"); + + b1.ToTable("MissionTask"); + + b1.WithOwner() + .HasForeignKey("MissionRunId"); + + 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.InspectionTarget#Position"); + + b2.WithOwner() + .HasForeignKey("MissionTaskId"); + }); + + b1.OwnsOne("Api.Database.Models.Pose", "RobotPose", b2 => + { + b2.Property("MissionTaskId") + .HasColumnType("nvarchar(450)"); + + b2.HasKey("MissionTaskId"); + + b2.ToTable("MissionTask.RobotPose#Pose"); + + 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.RobotPose#Pose.Orientation#Orientation"); + + 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.RobotPose#Pose.Position#Position"); + + 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("Area"); + + b.Navigation("MapMetadata"); + + b.Navigation("Robot"); + + b.Navigation("Tasks"); + }); + + modelBuilder.Entity("Api.Database.Models.Plant", b => + { + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Installation"); + }); + + modelBuilder.Entity("Api.Database.Models.Robot", b => + { + b.HasOne("Api.Database.Models.Area", "CurrentArea") + .WithMany() + .HasForeignKey("CurrentAreaId"); + + b.HasOne("Api.Database.Models.RobotModel", "Model") + .WithMany() + .HasForeignKey("ModelId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.OwnsOne("Api.Database.Models.Pose", "Pose", b1 => + { + b1.Property("RobotId") + .HasColumnType("nvarchar(450)"); + + b1.HasKey("RobotId"); + + b1.ToTable("Robot.Pose#Pose"); + + 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("Robot.Pose#Pose.Orientation#Orientation"); + + 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("Robot.Pose#Pose.Position#Position"); + + 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("CurrentArea"); + + b.Navigation("Model"); + + b.Navigation("Pose") + .IsRequired(); + + b.Navigation("VideoStreams"); + }); + + modelBuilder.Entity("Api.Database.Models.SafePosition", b => + { + b.HasOne("Api.Database.Models.Area", null) + .WithMany("SafePositions") + .HasForeignKey("AreaId"); + + b.OwnsOne("Api.Database.Models.Pose", "Pose", b1 => + { + b1.Property("SafePositionId") + .HasColumnType("nvarchar(450)"); + + b1.HasKey("SafePositionId"); + + b1.ToTable("SafePosition.Pose#Pose"); + + b1.WithOwner() + .HasForeignKey("SafePositionId"); + + b1.OwnsOne("Api.Database.Models.Orientation", "Orientation", b2 => + { + b2.Property("PoseSafePositionId") + .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("PoseSafePositionId"); + + b2.ToTable("SafePosition.Pose#Pose.Orientation#Orientation"); + + b2.WithOwner() + .HasForeignKey("PoseSafePositionId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "Position", b2 => + { + b2.Property("PoseSafePositionId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseSafePositionId"); + + b2.ToTable("SafePosition.Pose#Pose.Position#Position"); + + b2.WithOwner() + .HasForeignKey("PoseSafePositionId"); + }); + + b1.Navigation("Orientation") + .IsRequired(); + + b1.Navigation("Position") + .IsRequired(); + }); + + b.Navigation("Pose") + .IsRequired(); + }); + + modelBuilder.Entity("Api.Database.Models.Area", b => + { + b.Navigation("SafePositions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/api/Migrations/20230727084402_MissionRunAndAreaRefactor.cs b/backend/api/Migrations/20230727084402_MissionRunAndAreaRefactor.cs new file mode 100644 index 000000000..ad02d7ea1 --- /dev/null +++ b/backend/api/Migrations/20230727084402_MissionRunAndAreaRefactor.cs @@ -0,0 +1,1426 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Api.Migrations +{ + /// + public partial class MissionRunAndAreaRefactor : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_MissionTask_Missions_MissionId", + table: "MissionTask"); + + migrationBuilder.DropForeignKey( + name: "FK_Robots_AssetDecks_CurrentAssetDeckId", + table: "Robots"); + + migrationBuilder.DropForeignKey( + name: "FK_Robots_RobotModels_ModelId", + table: "Robots"); + + migrationBuilder.DropForeignKey( + name: "FK_SafePositions_AssetDecks_AssetDeckId", + table: "SafePositions"); + + migrationBuilder.DropForeignKey( + name: "FK_VideoStream_Robots_RobotId", + table: "VideoStream"); + + migrationBuilder.DropTable( + name: "Missions"); + + migrationBuilder.DropPrimaryKey( + name: "PK_SafePositions", + table: "SafePositions"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Robots", + table: "Robots"); + + migrationBuilder.DropPrimaryKey( + name: "PK_RobotModels", + table: "RobotModels"); + + migrationBuilder.DropPrimaryKey( + name: "PK_AssetDecks", + table: "AssetDecks"); + + migrationBuilder.DropIndex( + name: "IX_AssetDecks_AssetCode_DeckName", + table: "AssetDecks"); + + migrationBuilder.DropColumn( + name: "InspectionTarget_X", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "InspectionTarget_Y", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "InspectionTarget_Z", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "RobotPose_Orientation_W", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "RobotPose_Orientation_X", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "RobotPose_Orientation_Y", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "RobotPose_Orientation_Z", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "RobotPose_Position_X", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "RobotPose_Position_Y", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "RobotPose_Position_Z", + table: "MissionTask"); + + migrationBuilder.DropColumn( + name: "Pose_Orientation_W", + table: "SafePositions"); + + migrationBuilder.DropColumn( + name: "Pose_Orientation_X", + table: "SafePositions"); + + migrationBuilder.DropColumn( + name: "Pose_Orientation_Y", + table: "SafePositions"); + + migrationBuilder.DropColumn( + name: "Pose_Orientation_Z", + table: "SafePositions"); + + migrationBuilder.DropColumn( + name: "Pose_Position_X", + table: "SafePositions"); + + migrationBuilder.DropColumn( + name: "Pose_Position_Y", + table: "SafePositions"); + + migrationBuilder.DropColumn( + name: "Pose_Position_Z", + table: "SafePositions"); + + migrationBuilder.DropColumn( + name: "Pose_Orientation_W", + table: "Robots"); + + migrationBuilder.DropColumn( + name: "Pose_Orientation_X", + table: "Robots"); + + migrationBuilder.DropColumn( + name: "Pose_Orientation_Y", + table: "Robots"); + + migrationBuilder.DropColumn( + name: "Pose_Orientation_Z", + table: "Robots"); + + migrationBuilder.DropColumn( + name: "Pose_Position_X", + table: "Robots"); + + migrationBuilder.DropColumn( + name: "Pose_Position_Y", + table: "Robots"); + + migrationBuilder.DropColumn( + name: "Pose_Position_Z", + table: "Robots"); + + migrationBuilder.DropColumn( + name: "DefaultLocalizationPose_Orientation_W", + table: "AssetDecks"); + + migrationBuilder.DropColumn( + name: "DefaultLocalizationPose_Orientation_X", + table: "AssetDecks"); + + migrationBuilder.DropColumn( + name: "DefaultLocalizationPose_Orientation_Y", + table: "AssetDecks"); + + migrationBuilder.DropColumn( + name: "DefaultLocalizationPose_Orientation_Z", + table: "AssetDecks"); + + migrationBuilder.DropColumn( + name: "DefaultLocalizationPose_Position_X", + table: "AssetDecks"); + + migrationBuilder.DropColumn( + name: "DefaultLocalizationPose_Position_Y", + table: "AssetDecks"); + + migrationBuilder.DropColumn( + name: "DefaultLocalizationPose_Position_Z", + table: "AssetDecks"); + + migrationBuilder.RenameTable( + name: "SafePositions", + newName: "SafePosition"); + + migrationBuilder.RenameTable( + name: "Robots", + newName: "Robot"); + + migrationBuilder.RenameTable( + name: "RobotModels", + newName: "RobotModel"); + + migrationBuilder.RenameTable( + name: "AssetDecks", + newName: "AssetDeck"); + + migrationBuilder.RenameColumn( + name: "MissionId", + table: "MissionTask", + newName: "MissionRunId"); + + migrationBuilder.RenameIndex( + name: "IX_MissionTask_MissionId", + table: "MissionTask", + newName: "IX_MissionTask_MissionRunId"); + + migrationBuilder.RenameColumn( + name: "AssetDeckId", + table: "SafePosition", + newName: "AreaId"); + + migrationBuilder.RenameIndex( + name: "IX_SafePositions_AssetDeckId", + table: "SafePosition", + newName: "IX_SafePosition_AreaId"); + + migrationBuilder.RenameColumn( + name: "CurrentAssetDeckId", + table: "Robot", + newName: "CurrentAreaId"); + + migrationBuilder.RenameColumn( + name: "CurrentAsset", + table: "Robot", + newName: "CurrentInstallation"); + + migrationBuilder.RenameIndex( + name: "IX_Robots_ModelId", + table: "Robot", + newName: "IX_Robot_ModelId"); + + migrationBuilder.RenameIndex( + name: "IX_Robots_CurrentAssetDeckId", + table: "Robot", + newName: "IX_Robot_CurrentAreaId"); + + migrationBuilder.RenameIndex( + name: "IX_RobotModels_Type", + table: "RobotModel", + newName: "IX_RobotModel_Type"); + + migrationBuilder.AddPrimaryKey( + name: "PK_SafePosition", + table: "SafePosition", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Robot", + table: "Robot", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_RobotModel", + table: "RobotModel", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_AssetDeck", + table: "AssetDeck", + column: "Id"); + + migrationBuilder.CreateTable( + name: "Installation", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + InstallationCode = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Installation", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "MissionTask.InspectionTarget#Position", + columns: table => new + { + MissionTaskId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionTask.InspectionTarget#Position", x => x.MissionTaskId); + table.ForeignKey( + name: "FK_MissionTask.InspectionTarget#Position_MissionTask_MissionTaskId", + column: x => x.MissionTaskId, + principalTable: "MissionTask", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MissionTask.RobotPose#Pose", + columns: table => new + { + MissionTaskId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionTask.RobotPose#Pose", x => x.MissionTaskId); + table.ForeignKey( + name: "FK_MissionTask.RobotPose#Pose_MissionTask_MissionTaskId", + column: x => x.MissionTaskId, + principalTable: "MissionTask", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Robot.Pose#Pose", + columns: table => new + { + RobotId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Robot.Pose#Pose", x => x.RobotId); + table.ForeignKey( + name: "FK_Robot.Pose#Pose_Robot_RobotId", + column: x => x.RobotId, + principalTable: "Robot", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SafePosition.Pose#Pose", + columns: table => new + { + SafePositionId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SafePosition.Pose#Pose", x => x.SafePositionId); + table.ForeignKey( + name: "FK_SafePosition.Pose#Pose_SafePosition_SafePositionId", + column: x => x.SafePositionId, + principalTable: "SafePosition", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Source", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + SourceId = table.Column(type: "nvarchar(max)", nullable: false), + Type = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Source", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Plant", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + InstallationId = table.Column(type: "nvarchar(450)", nullable: true), + PlantCode = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Plant", x => x.Id); + table.ForeignKey( + name: "FK_Plant_Installation_InstallationId", + column: x => x.InstallationId, + principalTable: "Installation", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "MissionTask.RobotPose#Pose.Orientation#Orientation", + columns: table => new + { + PoseMissionTaskId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false), + W = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionTask.RobotPose#Pose.Orientation#Orientation", x => x.PoseMissionTaskId); + table.ForeignKey( + name: "FK_MissionTask.RobotPose#Pose.Orientation#Orientation_MissionTask.RobotPose#Pose_PoseMissionTaskId", + column: x => x.PoseMissionTaskId, + principalTable: "MissionTask.RobotPose#Pose", + principalColumn: "MissionTaskId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MissionTask.RobotPose#Pose.Position#Position", + columns: table => new + { + PoseMissionTaskId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionTask.RobotPose#Pose.Position#Position", x => x.PoseMissionTaskId); + table.ForeignKey( + name: "FK_MissionTask.RobotPose#Pose.Position#Position_MissionTask.RobotPose#Pose_PoseMissionTaskId", + column: x => x.PoseMissionTaskId, + principalTable: "MissionTask.RobotPose#Pose", + principalColumn: "MissionTaskId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Robot.Pose#Pose.Orientation#Orientation", + columns: table => new + { + PoseRobotId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false), + W = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Robot.Pose#Pose.Orientation#Orientation", x => x.PoseRobotId); + table.ForeignKey( + name: "FK_Robot.Pose#Pose.Orientation#Orientation_Robot.Pose#Pose_PoseRobotId", + column: x => x.PoseRobotId, + principalTable: "Robot.Pose#Pose", + principalColumn: "RobotId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Robot.Pose#Pose.Position#Position", + columns: table => new + { + PoseRobotId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Robot.Pose#Pose.Position#Position", x => x.PoseRobotId); + table.ForeignKey( + name: "FK_Robot.Pose#Pose.Position#Position_Robot.Pose#Pose_PoseRobotId", + column: x => x.PoseRobotId, + principalTable: "Robot.Pose#Pose", + principalColumn: "RobotId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SafePosition.Pose#Pose.Orientation#Orientation", + columns: table => new + { + PoseSafePositionId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false), + W = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SafePosition.Pose#Pose.Orientation#Orientation", x => x.PoseSafePositionId); + table.ForeignKey( + name: "FK_SafePosition.Pose#Pose.Orientation#Orientation_SafePosition.Pose#Pose_PoseSafePositionId", + column: x => x.PoseSafePositionId, + principalTable: "SafePosition.Pose#Pose", + principalColumn: "SafePositionId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SafePosition.Pose#Pose.Position#Position", + columns: table => new + { + PoseSafePositionId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SafePosition.Pose#Pose.Position#Position", x => x.PoseSafePositionId); + table.ForeignKey( + name: "FK_SafePosition.Pose#Pose.Position#Position_SafePosition.Pose#Pose_PoseSafePositionId", + column: x => x.PoseSafePositionId, + principalTable: "SafePosition.Pose#Pose", + principalColumn: "SafePositionId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Deck", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + PlantId = table.Column(type: "nvarchar(450)", nullable: true), + InstallationId = table.Column(type: "nvarchar(450)", nullable: true), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Deck", x => x.Id); + table.ForeignKey( + name: "FK_Deck_Installation_InstallationId", + column: x => x.InstallationId, + principalTable: "Installation", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Deck_Plant_PlantId", + column: x => x.PlantId, + principalTable: "Plant", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "Area", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + DeckId = table.Column(type: "nvarchar(450)", nullable: false), + PlantId = table.Column(type: "nvarchar(450)", nullable: false), + InstallationId = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Area", x => x.Id); + table.ForeignKey( + name: "FK_Area_Deck_DeckId", + column: x => x.DeckId, + principalTable: "Deck", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Area_Installation_InstallationId", + column: x => x.InstallationId, + principalTable: "Installation", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Area_Plant_PlantId", + column: x => x.PlantId, + principalTable: "Plant", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "Area.DefaultLocalizationPose#Pose", + columns: table => new + { + AreaId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Area.DefaultLocalizationPose#Pose", x => x.AreaId); + table.ForeignKey( + name: "FK_Area.DefaultLocalizationPose#Pose_Area_AreaId", + column: x => x.AreaId, + principalTable: "Area", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Area.MapMetadata#MapMetadata", + columns: table => new + { + AreaId = table.Column(type: "nvarchar(450)", nullable: false), + MapName = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Area.MapMetadata#MapMetadata", x => x.AreaId); + table.ForeignKey( + name: "FK_Area.MapMetadata#MapMetadata_Area_AreaId", + column: x => x.AreaId, + principalTable: "Area", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MissionRun", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + MissionId = table.Column(type: "nvarchar(max)", nullable: true), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + Status = table.Column(type: "int", nullable: false), + InstallationCode = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + DesiredStartTime = table.Column(type: "datetimeoffset", nullable: false), + RobotId = table.Column(type: "nvarchar(450)", nullable: false), + IsarMissionId = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + Description = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), + StatusReason = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), + Comment = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: true), + AreaId = table.Column(type: "nvarchar(450)", nullable: true), + StartTime = table.Column(type: "datetimeoffset", nullable: true), + EndTime = table.Column(type: "datetimeoffset", nullable: true), + EstimatedDuration = table.Column(type: "bigint", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionRun", x => x.Id); + table.ForeignKey( + name: "FK_MissionRun_Area_AreaId", + column: x => x.AreaId, + principalTable: "Area", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_MissionRun_Robot_RobotId", + column: x => x.RobotId, + principalTable: "Robot", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "Area.DefaultLocalizationPose#Pose.Orientation#Orientation", + columns: table => new + { + PoseAreaId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false), + W = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Area.DefaultLocalizationPose#Pose.Orientation#Orientation", x => x.PoseAreaId); + table.ForeignKey( + name: "FK_Area.DefaultLocalizationPose#Pose.Orientation#Orientation_Area.DefaultLocalizationPose#Pose_PoseAreaId", + column: x => x.PoseAreaId, + principalTable: "Area.DefaultLocalizationPose#Pose", + principalColumn: "AreaId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Area.DefaultLocalizationPose#Pose.Position#Position", + columns: table => new + { + PoseAreaId = table.Column(type: "nvarchar(450)", nullable: false), + X = table.Column(type: "real", nullable: false), + Y = table.Column(type: "real", nullable: false), + Z = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Area.DefaultLocalizationPose#Pose.Position#Position", x => x.PoseAreaId); + table.ForeignKey( + name: "FK_Area.DefaultLocalizationPose#Pose.Position#Position_Area.DefaultLocalizationPose#Pose_PoseAreaId", + column: x => x.PoseAreaId, + principalTable: "Area.DefaultLocalizationPose#Pose", + principalColumn: "AreaId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Area.MapMetadata#MapMetadata.Boundary#Boundary", + columns: table => new + { + MapMetadataAreaId = table.Column(type: "nvarchar(450)", nullable: false), + X1 = table.Column(type: "float", nullable: false), + X2 = table.Column(type: "float", nullable: false), + Y1 = table.Column(type: "float", nullable: false), + Y2 = table.Column(type: "float", nullable: false), + Z1 = table.Column(type: "float", nullable: false), + Z2 = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Area.MapMetadata#MapMetadata.Boundary#Boundary", x => x.MapMetadataAreaId); + table.ForeignKey( + name: "FK_Area.MapMetadata#MapMetadata.Boundary#Boundary_Area.MapMetadata#MapMetadata_MapMetadataAreaId", + column: x => x.MapMetadataAreaId, + principalTable: "Area.MapMetadata#MapMetadata", + principalColumn: "AreaId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Area.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices", + columns: table => new + { + MapMetadataAreaId = table.Column(type: "nvarchar(450)", nullable: false), + C1 = table.Column(type: "float", nullable: false), + C2 = table.Column(type: "float", nullable: false), + D1 = table.Column(type: "float", nullable: false), + D2 = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Area.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices", x => x.MapMetadataAreaId); + table.ForeignKey( + name: "FK_Area.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices_Area.MapMetadata#MapMetadata_MapMetadataAreaId", + column: x => x.MapMetadataAreaId, + principalTable: "Area.MapMetadata#MapMetadata", + principalColumn: "AreaId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MissionDefinition", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + SourceId = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + InstallationCode = table.Column(type: "nvarchar(max)", nullable: false), + Comment = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: true), + InspectionFrequency = table.Column(type: "time", nullable: true), + LastRunId = table.Column(type: "nvarchar(450)", nullable: true), + AreaId = table.Column(type: "nvarchar(450)", nullable: true), + IsDeprecated = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionDefinition", x => x.Id); + table.ForeignKey( + name: "FK_MissionDefinition_Area_AreaId", + column: x => x.AreaId, + principalTable: "Area", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_MissionDefinition_MissionRun_LastRunId", + column: x => x.LastRunId, + principalTable: "MissionRun", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_MissionDefinition_Source_SourceId", + column: x => x.SourceId, + principalTable: "Source", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "MissionRun.MapMetadata#MapMetadata", + columns: table => new + { + MissionRunId = table.Column(type: "nvarchar(450)", nullable: false), + MapName = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionRun.MapMetadata#MapMetadata", x => x.MissionRunId); + table.ForeignKey( + name: "FK_MissionRun.MapMetadata#MapMetadata_MissionRun_MissionRunId", + column: x => x.MissionRunId, + principalTable: "MissionRun", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MissionRun.MapMetadata#MapMetadata.Boundary#Boundary", + columns: table => new + { + MapMetadataMissionRunId = table.Column(type: "nvarchar(450)", nullable: false), + X1 = table.Column(type: "float", nullable: false), + X2 = table.Column(type: "float", nullable: false), + Y1 = table.Column(type: "float", nullable: false), + Y2 = table.Column(type: "float", nullable: false), + Z1 = table.Column(type: "float", nullable: false), + Z2 = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionRun.MapMetadata#MapMetadata.Boundary#Boundary", x => x.MapMetadataMissionRunId); + table.ForeignKey( + name: "FK_MissionRun.MapMetadata#MapMetadata.Boundary#Boundary_MissionRun.MapMetadata#MapMetadata_MapMetadataMissionRunId", + column: x => x.MapMetadataMissionRunId, + principalTable: "MissionRun.MapMetadata#MapMetadata", + principalColumn: "MissionRunId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MissionRun.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices", + columns: table => new + { + MapMetadataMissionRunId = table.Column(type: "nvarchar(450)", nullable: false), + C1 = table.Column(type: "float", nullable: false), + C2 = table.Column(type: "float", nullable: false), + D1 = table.Column(type: "float", nullable: false), + D2 = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MissionRun.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices", x => x.MapMetadataMissionRunId); + table.ForeignKey( + name: "FK_MissionRun.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices_MissionRun.MapMetadata#MapMetadata_MapMetad~", + column: x => x.MapMetadataMissionRunId, + principalTable: "MissionRun.MapMetadata#MapMetadata", + principalColumn: "MissionRunId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Area_DeckId", + table: "Area", + column: "DeckId"); + + migrationBuilder.CreateIndex( + name: "IX_Area_InstallationId", + table: "Area", + column: "InstallationId"); + + migrationBuilder.CreateIndex( + name: "IX_Area_PlantId", + table: "Area", + column: "PlantId"); + + migrationBuilder.CreateIndex( + name: "IX_Deck_InstallationId", + table: "Deck", + column: "InstallationId"); + + migrationBuilder.CreateIndex( + name: "IX_Deck_PlantId", + table: "Deck", + column: "PlantId"); + + migrationBuilder.CreateIndex( + name: "IX_Installation_InstallationCode", + table: "Installation", + column: "InstallationCode", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_MissionDefinition_AreaId", + table: "MissionDefinition", + column: "AreaId"); + + migrationBuilder.CreateIndex( + name: "IX_MissionDefinition_LastRunId", + table: "MissionDefinition", + column: "LastRunId"); + + migrationBuilder.CreateIndex( + name: "IX_MissionDefinition_SourceId", + table: "MissionDefinition", + column: "SourceId"); + + migrationBuilder.CreateIndex( + name: "IX_MissionRun_AreaId", + table: "MissionRun", + column: "AreaId"); + + migrationBuilder.CreateIndex( + name: "IX_MissionRun_RobotId", + table: "MissionRun", + column: "RobotId"); + + migrationBuilder.CreateIndex( + name: "IX_Plant_InstallationId", + table: "Plant", + column: "InstallationId"); + + migrationBuilder.CreateIndex( + name: "IX_Plant_PlantCode", + table: "Plant", + column: "PlantCode", + unique: true); + + migrationBuilder.AddForeignKey( + name: "FK_MissionTask_MissionRun_MissionRunId", + table: "MissionTask", + column: "MissionRunId", + principalTable: "MissionRun", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Robot_Area_CurrentAreaId", + table: "Robot", + column: "CurrentAreaId", + principalTable: "Area", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Robot_RobotModel_ModelId", + table: "Robot", + column: "ModelId", + principalTable: "RobotModel", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_SafePosition_Area_AreaId", + table: "SafePosition", + column: "AreaId", + principalTable: "Area", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_VideoStream_Robot_RobotId", + table: "VideoStream", + column: "RobotId", + principalTable: "Robot", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_MissionTask_MissionRun_MissionRunId", + table: "MissionTask"); + + migrationBuilder.DropForeignKey( + name: "FK_Robot_Area_CurrentAreaId", + table: "Robot"); + + migrationBuilder.DropForeignKey( + name: "FK_Robot_RobotModel_ModelId", + table: "Robot"); + + migrationBuilder.DropForeignKey( + name: "FK_SafePosition_Area_AreaId", + table: "SafePosition"); + + migrationBuilder.DropForeignKey( + name: "FK_VideoStream_Robot_RobotId", + table: "VideoStream"); + + migrationBuilder.DropTable( + name: "Area.DefaultLocalizationPose#Pose.Orientation#Orientation"); + + migrationBuilder.DropTable( + name: "Area.DefaultLocalizationPose#Pose.Position#Position"); + + migrationBuilder.DropTable( + name: "Area.MapMetadata#MapMetadata.Boundary#Boundary"); + + migrationBuilder.DropTable( + name: "Area.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices"); + + migrationBuilder.DropTable( + name: "MissionDefinition"); + + migrationBuilder.DropTable( + name: "MissionRun.MapMetadata#MapMetadata.Boundary#Boundary"); + + migrationBuilder.DropTable( + name: "MissionRun.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices"); + + migrationBuilder.DropTable( + name: "MissionTask.InspectionTarget#Position"); + + migrationBuilder.DropTable( + name: "MissionTask.RobotPose#Pose.Orientation#Orientation"); + + migrationBuilder.DropTable( + name: "MissionTask.RobotPose#Pose.Position#Position"); + + migrationBuilder.DropTable( + name: "Robot.Pose#Pose.Orientation#Orientation"); + + migrationBuilder.DropTable( + name: "Robot.Pose#Pose.Position#Position"); + + migrationBuilder.DropTable( + name: "SafePosition.Pose#Pose.Orientation#Orientation"); + + migrationBuilder.DropTable( + name: "SafePosition.Pose#Pose.Position#Position"); + + migrationBuilder.DropTable( + name: "Area.DefaultLocalizationPose#Pose"); + + migrationBuilder.DropTable( + name: "Area.MapMetadata#MapMetadata"); + + migrationBuilder.DropTable( + name: "Source"); + + migrationBuilder.DropTable( + name: "MissionRun.MapMetadata#MapMetadata"); + + migrationBuilder.DropTable( + name: "MissionTask.RobotPose#Pose"); + + migrationBuilder.DropTable( + name: "Robot.Pose#Pose"); + + migrationBuilder.DropTable( + name: "SafePosition.Pose#Pose"); + + migrationBuilder.DropTable( + name: "MissionRun"); + + migrationBuilder.DropTable( + name: "Area"); + + migrationBuilder.DropTable( + name: "Deck"); + + migrationBuilder.DropTable( + name: "Plant"); + + migrationBuilder.DropTable( + name: "Installation"); + + migrationBuilder.DropPrimaryKey( + name: "PK_SafePosition", + table: "SafePosition"); + + migrationBuilder.DropPrimaryKey( + name: "PK_RobotModel", + table: "RobotModel"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Robot", + table: "Robot"); + + migrationBuilder.DropPrimaryKey( + name: "PK_AssetDeck", + table: "AssetDeck"); + + migrationBuilder.RenameTable( + name: "SafePosition", + newName: "SafePositions"); + + migrationBuilder.RenameTable( + name: "RobotModel", + newName: "RobotModels"); + + migrationBuilder.RenameTable( + name: "Robot", + newName: "Robots"); + + migrationBuilder.RenameTable( + name: "AssetDeck", + newName: "AssetDecks"); + + migrationBuilder.RenameColumn( + name: "MissionRunId", + table: "MissionTask", + newName: "MissionId"); + + migrationBuilder.RenameIndex( + name: "IX_MissionTask_MissionRunId", + table: "MissionTask", + newName: "IX_MissionTask_MissionId"); + + migrationBuilder.RenameColumn( + name: "AreaId", + table: "SafePositions", + newName: "AssetDeckId"); + + migrationBuilder.RenameIndex( + name: "IX_SafePosition_AreaId", + table: "SafePositions", + newName: "IX_SafePositions_AssetDeckId"); + + migrationBuilder.RenameIndex( + name: "IX_RobotModel_Type", + table: "RobotModels", + newName: "IX_RobotModels_Type"); + + migrationBuilder.RenameColumn( + name: "CurrentInstallation", + table: "Robots", + newName: "CurrentAsset"); + + migrationBuilder.RenameColumn( + name: "CurrentAreaId", + table: "Robots", + newName: "CurrentAssetDeckId"); + + migrationBuilder.RenameIndex( + name: "IX_Robot_ModelId", + table: "Robots", + newName: "IX_Robots_ModelId"); + + migrationBuilder.RenameIndex( + name: "IX_Robot_CurrentAreaId", + table: "Robots", + newName: "IX_Robots_CurrentAssetDeckId"); + + migrationBuilder.AddColumn( + name: "InspectionTarget_X", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "InspectionTarget_Y", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "InspectionTarget_Z", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "RobotPose_Orientation_W", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "RobotPose_Orientation_X", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "RobotPose_Orientation_Y", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "RobotPose_Orientation_Z", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "RobotPose_Position_X", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "RobotPose_Position_Y", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "RobotPose_Position_Z", + table: "MissionTask", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Orientation_W", + table: "SafePositions", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Orientation_X", + table: "SafePositions", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Orientation_Y", + table: "SafePositions", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Orientation_Z", + table: "SafePositions", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Position_X", + table: "SafePositions", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Position_Y", + table: "SafePositions", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Position_Z", + table: "SafePositions", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Orientation_W", + table: "Robots", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Orientation_X", + table: "Robots", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Orientation_Y", + table: "Robots", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Orientation_Z", + table: "Robots", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Position_X", + table: "Robots", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Position_Y", + table: "Robots", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Pose_Position_Z", + table: "Robots", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "DefaultLocalizationPose_Orientation_W", + table: "AssetDecks", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "DefaultLocalizationPose_Orientation_X", + table: "AssetDecks", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "DefaultLocalizationPose_Orientation_Y", + table: "AssetDecks", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "DefaultLocalizationPose_Orientation_Z", + table: "AssetDecks", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "DefaultLocalizationPose_Position_X", + table: "AssetDecks", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "DefaultLocalizationPose_Position_Y", + table: "AssetDecks", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "DefaultLocalizationPose_Position_Z", + table: "AssetDecks", + type: "real", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddPrimaryKey( + name: "PK_SafePositions", + table: "SafePositions", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_RobotModels", + table: "RobotModels", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Robots", + table: "Robots", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_AssetDecks", + table: "AssetDecks", + column: "Id"); + + migrationBuilder.CreateTable( + name: "Missions", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + RobotId = table.Column(type: "nvarchar(450)", nullable: false), + AssetCode = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + Comment = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: true), + Description = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), + DesiredStartTime = table.Column(type: "datetimeoffset", nullable: false), + EchoMissionId = table.Column(type: "int", maxLength: 200, nullable: true), + EndTime = table.Column(type: "datetimeoffset", nullable: true), + EstimatedDuration = table.Column(type: "bigint", nullable: true), + IsarMissionId = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + StartTime = table.Column(type: "datetimeoffset", nullable: true), + Status = table.Column(type: "int", nullable: false), + StatusReason = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), + MapMetadata_MapName = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + MapMetadata_Boundary_X1 = table.Column(type: "float", nullable: true), + MapMetadata_Boundary_X2 = table.Column(type: "float", nullable: true), + MapMetadata_Boundary_Y1 = table.Column(type: "float", nullable: true), + MapMetadata_Boundary_Y2 = table.Column(type: "float", nullable: true), + MapMetadata_Boundary_Z1 = table.Column(type: "float", nullable: true), + MapMetadata_Boundary_Z2 = table.Column(type: "float", nullable: true), + MapMetadata_TransformationMatrices_C1 = table.Column(type: "float", nullable: true), + MapMetadata_TransformationMatrices_C2 = table.Column(type: "float", nullable: true), + MapMetadata_TransformationMatrices_D1 = table.Column(type: "float", nullable: true), + MapMetadata_TransformationMatrices_D2 = table.Column(type: "float", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Missions", x => x.Id); + table.ForeignKey( + name: "FK_Missions_Robots_RobotId", + column: x => x.RobotId, + principalTable: "Robots", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AssetDecks_AssetCode_DeckName", + table: "AssetDecks", + columns: new[] { "AssetCode", "DeckName" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Missions_RobotId", + table: "Missions", + column: "RobotId"); + + migrationBuilder.AddForeignKey( + name: "FK_MissionTask_Missions_MissionId", + table: "MissionTask", + column: "MissionId", + principalTable: "Missions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Robots_AssetDecks_CurrentAssetDeckId", + table: "Robots", + column: "CurrentAssetDeckId", + principalTable: "AssetDecks", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Robots_RobotModels_ModelId", + table: "Robots", + column: "ModelId", + principalTable: "RobotModels", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_SafePositions_AssetDecks_AssetDeckId", + table: "SafePositions", + column: "AssetDeckId", + principalTable: "AssetDecks", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_VideoStream_Robots_RobotId", + table: "VideoStream", + column: "RobotId", + principalTable: "Robots", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs b/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs index 1a1f553b8..eb39638dd 100644 --- a/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs +++ b/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs @@ -17,10 +17,44 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.13") + .HasAnnotation("ProductVersion", "7.0.8") .HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Api.Database.Models.Area", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("DeckId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("DeckId"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantId"); + + b.ToTable("Area"); + }); modelBuilder.Entity("Api.Database.Models.AssetDeck", b => { @@ -40,23 +74,114 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("AssetCode", "DeckName") + b.ToTable("AssetDeck"); + }); + + modelBuilder.Entity("Api.Database.Models.Deck", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantId"); + + b.ToTable("Deck"); + }); + + modelBuilder.Entity("Api.Database.Models.Installation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationCode") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationCode") .IsUnique(); - b.ToTable("AssetDecks"); + b.ToTable("Installation"); }); - modelBuilder.Entity("Api.Database.Models.Mission", b => + modelBuilder.Entity("Api.Database.Models.MissionDefinition", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("nvarchar(450)"); - b.Property("AssetCode") + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("Comment") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("InspectionFrequency") + .HasColumnType("time"); + + b.Property("InstallationCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeprecated") + .HasColumnType("bit"); + + b.Property("LastRunId") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") .IsRequired() .HasMaxLength(200) .HasColumnType("nvarchar(200)"); + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("AreaId"); + + b.HasIndex("LastRunId"); + + b.HasIndex("SourceId"); + + b.ToTable("MissionDefinition"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionRun", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + b.Property("Comment") .HasMaxLength(1000) .HasColumnType("nvarchar(1000)"); @@ -68,20 +193,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("DesiredStartTime") .HasColumnType("datetimeoffset"); - b.Property("EchoMissionId") - .HasMaxLength(200) - .HasColumnType("int"); - b.Property("EndTime") .HasColumnType("datetimeoffset"); b.Property("EstimatedDuration") .HasColumnType("bigint"); + b.Property("InstallationCode") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + b.Property("IsarMissionId") .HasMaxLength(200) .HasColumnType("nvarchar(200)"); + b.Property("MissionId") + .HasColumnType("nvarchar(max)"); + b.Property("Name") .IsRequired() .HasMaxLength(200) @@ -103,9 +232,40 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("AreaId"); + b.HasIndex("RobotId"); - b.ToTable("Missions"); + b.ToTable("MissionRun"); + }); + + modelBuilder.Entity("Api.Database.Models.Plant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantCode") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantCode") + .IsUnique(); + + b.ToTable("Plant"); }); modelBuilder.Entity("Api.Database.Models.Robot", b => @@ -117,13 +277,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("BatteryLevel") .HasColumnType("real"); - b.Property("CurrentAsset") + b.Property("CurrentAreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("CurrentInstallation") .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("CurrentAssetDeckId") - .HasColumnType("nvarchar(450)"); - b.Property("CurrentMissionId") .HasColumnType("nvarchar(max)"); @@ -165,11 +325,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("CurrentAssetDeckId"); + b.HasIndex("CurrentAreaId"); b.HasIndex("ModelId"); - b.ToTable("Robots"); + b.ToTable("Robot"); }); modelBuilder.Entity("Api.Database.Models.RobotModel", b => @@ -199,7 +359,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("Type") .IsUnique(); - b.ToTable("RobotModels"); + b.ToTable("RobotModel"); }); modelBuilder.Entity("Api.Database.Models.SafePosition", b => @@ -208,33 +368,69 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("nvarchar(450)"); - b.Property("AssetDeckId") + b.Property("AreaId") .HasColumnType("nvarchar(450)"); b.HasKey("Id"); - b.HasIndex("AssetDeckId"); + b.HasIndex("AreaId"); - b.ToTable("SafePositions"); + b.ToTable("SafePosition"); }); - modelBuilder.Entity("Api.Database.Models.AssetDeck", b => + modelBuilder.Entity("Api.Database.Models.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Source"); + }); + + modelBuilder.Entity("Api.Database.Models.Area", b => { + b.HasOne("Api.Database.Models.Deck", "Deck") + .WithMany() + .HasForeignKey("DeckId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Api.Database.Models.Plant", "Plant") + .WithMany() + .HasForeignKey("PlantId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + b.OwnsOne("Api.Database.Models.Pose", "DefaultLocalizationPose", b1 => { - b1.Property("AssetDeckId") + b1.Property("AreaId") .HasColumnType("nvarchar(450)"); - b1.HasKey("AssetDeckId"); + b1.HasKey("AreaId"); - b1.ToTable("AssetDecks"); + b1.ToTable("Area.DefaultLocalizationPose#Pose"); b1.WithOwner() - .HasForeignKey("AssetDeckId"); + .HasForeignKey("AreaId"); b1.OwnsOne("Api.Database.Models.Orientation", "Orientation", b2 => { - b2.Property("PoseAssetDeckId") + b2.Property("PoseAreaId") .HasColumnType("nvarchar(450)"); b2.Property("W") @@ -249,17 +445,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.Property("Z") .HasColumnType("real"); - b2.HasKey("PoseAssetDeckId"); + b2.HasKey("PoseAreaId"); - b2.ToTable("AssetDecks"); + b2.ToTable("Area.DefaultLocalizationPose#Pose.Orientation#Orientation"); b2.WithOwner() - .HasForeignKey("PoseAssetDeckId"); + .HasForeignKey("PoseAreaId"); }); b1.OwnsOne("Api.Database.Models.Position", "Position", b2 => { - b2.Property("PoseAssetDeckId") + b2.Property("PoseAreaId") .HasColumnType("nvarchar(450)"); b2.Property("X") @@ -271,12 +467,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.Property("Z") .HasColumnType("real"); - b2.HasKey("PoseAssetDeckId"); + b2.HasKey("PoseAreaId"); - b2.ToTable("AssetDecks"); + b2.ToTable("Area.DefaultLocalizationPose#Pose.Position#Position"); b2.WithOwner() - .HasForeignKey("PoseAssetDeckId"); + .HasForeignKey("PoseAreaId"); }); b1.Navigation("Orientation") @@ -286,21 +482,154 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); + b.OwnsOne("Api.Database.Models.MapMetadata", "MapMetadata", b1 => + { + b1.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b1.Property("MapName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.HasKey("AreaId"); + + b1.ToTable("Area.MapMetadata#MapMetadata"); + + b1.WithOwner() + .HasForeignKey("AreaId"); + + b1.OwnsOne("Api.Database.Models.Boundary", "Boundary", b2 => + { + b2.Property("MapMetadataAreaId") + .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("MapMetadataAreaId"); + + b2.ToTable("Area.MapMetadata#MapMetadata.Boundary#Boundary"); + + b2.WithOwner() + .HasForeignKey("MapMetadataAreaId"); + }); + + b1.OwnsOne("Api.Database.Models.TransformationMatrices", "TransformationMatrices", b2 => + { + b2.Property("MapMetadataAreaId") + .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("MapMetadataAreaId"); + + b2.ToTable("Area.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices"); + + b2.WithOwner() + .HasForeignKey("MapMetadataAreaId"); + }); + + b1.Navigation("Boundary") + .IsRequired(); + + b1.Navigation("TransformationMatrices") + .IsRequired(); + }); + + b.Navigation("Deck"); + b.Navigation("DefaultLocalizationPose") .IsRequired(); + + b.Navigation("Installation"); + + b.Navigation("MapMetadata") + .IsRequired(); + + b.Navigation("Plant"); + }); + + modelBuilder.Entity("Api.Database.Models.Deck", b => + { + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Api.Database.Models.Plant", "Plant") + .WithMany() + .HasForeignKey("PlantId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Installation"); + + b.Navigation("Plant"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionDefinition", b => + { + b.HasOne("Api.Database.Models.Area", "Area") + .WithMany() + .HasForeignKey("AreaId"); + + b.HasOne("Api.Database.Models.MissionRun", "LastRun") + .WithMany() + .HasForeignKey("LastRunId"); + + b.HasOne("Api.Database.Models.Source", "Source") + .WithMany() + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Area"); + + b.Navigation("LastRun"); + + b.Navigation("Source"); }); - modelBuilder.Entity("Api.Database.Models.Mission", b => + modelBuilder.Entity("Api.Database.Models.MissionRun", b => { + b.HasOne("Api.Database.Models.Area", "Area") + .WithMany() + .HasForeignKey("AreaId"); + b.HasOne("Api.Database.Models.Robot", "Robot") .WithMany() .HasForeignKey("RobotId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.Restrict) .IsRequired(); b.OwnsOne("Api.Database.Models.MapMetadata", "MapMetadata", b1 => { - b1.Property("MissionId") + b1.Property("MissionRunId") .HasColumnType("nvarchar(450)"); b1.Property("MapName") @@ -308,16 +637,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(200) .HasColumnType("nvarchar(200)"); - b1.HasKey("MissionId"); + b1.HasKey("MissionRunId"); - b1.ToTable("Missions"); + b1.ToTable("MissionRun.MapMetadata#MapMetadata"); b1.WithOwner() - .HasForeignKey("MissionId"); + .HasForeignKey("MissionRunId"); b1.OwnsOne("Api.Database.Models.Boundary", "Boundary", b2 => { - b2.Property("MapMetadataMissionId") + b2.Property("MapMetadataMissionRunId") .HasColumnType("nvarchar(450)"); b2.Property("X1") @@ -338,17 +667,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.Property("Z2") .HasColumnType("float"); - b2.HasKey("MapMetadataMissionId"); + b2.HasKey("MapMetadataMissionRunId"); - b2.ToTable("Missions"); + b2.ToTable("MissionRun.MapMetadata#MapMetadata.Boundary#Boundary"); b2.WithOwner() - .HasForeignKey("MapMetadataMissionId"); + .HasForeignKey("MapMetadataMissionRunId"); }); b1.OwnsOne("Api.Database.Models.TransformationMatrices", "TransformationMatrices", b2 => { - b2.Property("MapMetadataMissionId") + b2.Property("MapMetadataMissionRunId") .HasColumnType("nvarchar(450)"); b2.Property("C1") @@ -363,12 +692,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.Property("D2") .HasColumnType("float"); - b2.HasKey("MapMetadataMissionId"); + b2.HasKey("MapMetadataMissionRunId"); - b2.ToTable("Missions"); + b2.ToTable("MissionRun.MapMetadata#MapMetadata.TransformationMatrices#TransformationMatrices"); b2.WithOwner() - .HasForeignKey("MapMetadataMissionId"); + .HasForeignKey("MapMetadataMissionRunId"); }); b1.Navigation("Boundary") @@ -402,7 +731,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(200) .HasColumnType("nvarchar(200)"); - b1.Property("MissionId") + b1.Property("MissionRunId") .IsRequired() .HasColumnType("nvarchar(450)"); @@ -421,12 +750,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b1.HasKey("Id"); - b1.HasIndex("MissionId"); + b1.HasIndex("MissionRunId"); b1.ToTable("MissionTask"); b1.WithOwner() - .HasForeignKey("MissionId"); + .HasForeignKey("MissionRunId"); b1.OwnsMany("Api.Database.Models.Inspection", "Inspections", b2 => { @@ -491,7 +820,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.HasKey("MissionTaskId"); - b2.ToTable("MissionTask"); + b2.ToTable("MissionTask.InspectionTarget#Position"); b2.WithOwner() .HasForeignKey("MissionTaskId"); @@ -504,7 +833,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.HasKey("MissionTaskId"); - b2.ToTable("MissionTask"); + b2.ToTable("MissionTask.RobotPose#Pose"); b2.WithOwner() .HasForeignKey("MissionTaskId"); @@ -528,7 +857,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b3.HasKey("PoseMissionTaskId"); - b3.ToTable("MissionTask"); + b3.ToTable("MissionTask.RobotPose#Pose.Orientation#Orientation"); b3.WithOwner() .HasForeignKey("PoseMissionTaskId"); @@ -550,7 +879,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b3.HasKey("PoseMissionTaskId"); - b3.ToTable("MissionTask"); + b3.ToTable("MissionTask.RobotPose#Pose.Position#Position"); b3.WithOwner() .HasForeignKey("PoseMissionTaskId"); @@ -572,6 +901,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); + b.Navigation("Area"); + b.Navigation("MapMetadata"); b.Navigation("Robot"); @@ -579,16 +910,26 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Tasks"); }); + modelBuilder.Entity("Api.Database.Models.Plant", b => + { + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Installation"); + }); + modelBuilder.Entity("Api.Database.Models.Robot", b => { - b.HasOne("Api.Database.Models.AssetDeck", "CurrentAssetDeck") + b.HasOne("Api.Database.Models.Area", "CurrentArea") .WithMany() - .HasForeignKey("CurrentAssetDeckId"); + .HasForeignKey("CurrentAreaId"); b.HasOne("Api.Database.Models.RobotModel", "Model") .WithMany() .HasForeignKey("ModelId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.Restrict) .IsRequired(); b.OwnsOne("Api.Database.Models.Pose", "Pose", b1 => @@ -598,7 +939,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b1.HasKey("RobotId"); - b1.ToTable("Robots"); + b1.ToTable("Robot.Pose#Pose"); b1.WithOwner() .HasForeignKey("RobotId"); @@ -622,7 +963,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.HasKey("PoseRobotId"); - b2.ToTable("Robots"); + b2.ToTable("Robot.Pose#Pose.Orientation#Orientation"); b2.WithOwner() .HasForeignKey("PoseRobotId"); @@ -644,7 +985,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.HasKey("PoseRobotId"); - b2.ToTable("Robots"); + b2.ToTable("Robot.Pose#Pose.Position#Position"); b2.WithOwner() .HasForeignKey("PoseRobotId"); @@ -695,7 +1036,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasForeignKey("RobotId"); }); - b.Navigation("CurrentAssetDeck"); + b.Navigation("CurrentArea"); b.Navigation("Model"); @@ -707,9 +1048,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Api.Database.Models.SafePosition", b => { - b.HasOne("Api.Database.Models.AssetDeck", null) + b.HasOne("Api.Database.Models.Area", null) .WithMany("SafePositions") - .HasForeignKey("AssetDeckId"); + .HasForeignKey("AreaId"); b.OwnsOne("Api.Database.Models.Pose", "Pose", b1 => { @@ -718,7 +1059,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b1.HasKey("SafePositionId"); - b1.ToTable("SafePositions"); + b1.ToTable("SafePosition.Pose#Pose"); b1.WithOwner() .HasForeignKey("SafePositionId"); @@ -742,7 +1083,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.HasKey("PoseSafePositionId"); - b2.ToTable("SafePositions"); + b2.ToTable("SafePosition.Pose#Pose.Orientation#Orientation"); b2.WithOwner() .HasForeignKey("PoseSafePositionId"); @@ -764,7 +1105,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b2.HasKey("PoseSafePositionId"); - b2.ToTable("SafePositions"); + b2.ToTable("SafePosition.Pose#Pose.Position#Position"); b2.WithOwner() .HasForeignKey("PoseSafePositionId"); @@ -781,7 +1122,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); - modelBuilder.Entity("Api.Database.Models.AssetDeck", b => + modelBuilder.Entity("Api.Database.Models.Area", b => { b.Navigation("SafePositions"); }); diff --git a/backend/api/api.csproj b/backend/api/api.csproj index 334af6d55..7df3efc30 100644 --- a/backend/api/api.csproj +++ b/backend/api/api.csproj @@ -16,12 +16,12 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + diff --git a/frontend/src/components/Pages/RobotPage/LocalizationDialog.tsx b/frontend/src/components/Pages/RobotPage/LocalizationDialog.tsx index 5d977126c..256279c25 100644 --- a/frontend/src/components/Pages/RobotPage/LocalizationDialog.tsx +++ b/frontend/src/components/Pages/RobotPage/LocalizationDialog.tsx @@ -96,8 +96,7 @@ export const LocalizationDialog = ({ robot }: RobotProps): JSX.Element => { const getAreaNames = (areas: Area[]): Map => { var areaNameMap = new Map() - areas.forEach((area: Area) => - areaNameMap.set(area.deckName, area)) + areas.forEach((area: Area) => areaNameMap.set(area.deckName, area)) return areaNameMap }