Skip to content

Commit

Permalink
Rename instead of replace mission table
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Jul 27, 2023
1 parent 00118e1 commit 4b62494
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 93 deletions.
9 changes: 0 additions & 9 deletions backend/api/Database/Context/FlotillaDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Deck>().HasOne(d => d.Plant).WithMany().OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Deck>().HasOne(d => d.Installation).WithMany().OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Plant>().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
Expand Down
120 changes: 36 additions & 84 deletions backend/api/Migrations/20230727084402_MissionRunAndAreaRefactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "FK_VideoStream_Robots_RobotId",
table: "VideoStream");

migrationBuilder.DropTable(
name: "Missions");

migrationBuilder.DropPrimaryKey(
name: "PK_SafePositions",
table: "SafePositions");

migrationBuilder.DropForeignKey(
name: "FK_Missions_Robots_RobotId",
table: "Missions"
);

migrationBuilder.DropPrimaryKey(
name: "PK_Robots",
table: "Robots");
Expand Down Expand Up @@ -178,6 +180,29 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "DefaultLocalizationPose_Position_Z",
table: "AssetDecks");

migrationBuilder.DropColumn(
name: "EchoMissionId",
table: "Missions"
);

migrationBuilder.RenameColumn(
name: "AssetCode",
table: "Missions",
newName: "InstallationCode"
);

migrationBuilder.AddColumn<string>(
name: "AreaId",
table: "Missions",
type: "nvarchar(450)",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "MissionId",
table: "Missions",
type: "nvarchar(max)",
nullable: true);

migrationBuilder.RenameTable(
name: "SafePositions",
newName: "SafePosition");
Expand All @@ -194,6 +219,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "AssetDecks",
newName: "AssetDeck");

migrationBuilder.RenameTable(
name: "Missions",
newName: "MissionRun");

migrationBuilder.RenameColumn(
name: "MissionId",
table: "MissionTask",
Expand Down Expand Up @@ -593,42 +622,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateTable(
name: "MissionRun",
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
MissionId = table.Column<string>(type: "nvarchar(max)", nullable: true),
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
InstallationCode = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
DesiredStartTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
RobotId = table.Column<string>(type: "nvarchar(450)", nullable: false),
IsarMissionId = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
Description = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
StatusReason = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
Comment = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
AreaId = table.Column<string>(type: "nvarchar(450)", nullable: true),
StartTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
EndTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
EstimatedDuration = table.Column<long>(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
Expand Down Expand Up @@ -1332,63 +1325,22 @@ protected override void Down(MigrationBuilder migrationBuilder)
table: "AssetDecks",
column: "Id");

migrationBuilder.CreateTable(
name: "Missions",
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
RobotId = table.Column<string>(type: "nvarchar(450)", nullable: false),
AssetCode = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
Comment = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
Description = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
DesiredStartTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
EchoMissionId = table.Column<int>(type: "int", maxLength: 200, nullable: true),
EndTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
EstimatedDuration = table.Column<long>(type: "bigint", nullable: true),
IsarMissionId = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
StartTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
Status = table.Column<int>(type: "int", nullable: false),
StatusReason = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
MapMetadata_MapName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
MapMetadata_Boundary_X1 = table.Column<double>(type: "float", nullable: true),
MapMetadata_Boundary_X2 = table.Column<double>(type: "float", nullable: true),
MapMetadata_Boundary_Y1 = table.Column<double>(type: "float", nullable: true),
MapMetadata_Boundary_Y2 = table.Column<double>(type: "float", nullable: true),
MapMetadata_Boundary_Z1 = table.Column<double>(type: "float", nullable: true),
MapMetadata_Boundary_Z2 = table.Column<double>(type: "float", nullable: true),
MapMetadata_TransformationMatrices_C1 = table.Column<double>(type: "float", nullable: true),
MapMetadata_TransformationMatrices_C2 = table.Column<double>(type: "float", nullable: true),
MapMetadata_TransformationMatrices_D1 = table.Column<double>(type: "float", nullable: true),
MapMetadata_TransformationMatrices_D2 = table.Column<double>(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",
name: "IX_MissionRun_RobotId",
table: "MissionRun",
column: "RobotId");

migrationBuilder.AddForeignKey(
name: "FK_MissionTask_Missions_MissionId",
name: "FK_MissionTask_MissionRun_MissionId",
table: "MissionTask",
column: "MissionId",
principalTable: "Missions",
principalTable: "MissionRun",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);

Expand Down

0 comments on commit 4b62494

Please sign in to comment.